.NET implementations that help for better interaction with various IoT devices (LED, displays, keyboards, sensors, etc).
- Platform: netstandard2.0;
- Distributed via NuGet (check out Menaver.IoT.Devices)
- This repository leverages Github Actions (GHA);
- 💡 Light-emitting diode (LED)
- ⌨️ Matrix Keyboard M×N
- 📟 Liquid-crystal display (LCD): PCF8574, PCF8575, PCA8574, PCA8575
- 🌡️ Humidity & Temperature Sensor (DHT): DHT11, DHT12, DHT21, DHT22
More examples of using the IoT devices can be found in the test project Menaver.IoT.Devices.Tests.
List<Led> leds = new()
{
new Led(4, Color.Red, false),
};
using var ledPanel = new LedPanel(leds);
ledPanel.SetAll(Color.Red);
await Task.Delay(300);
ledPanel.ResetAll();
await Task.Delay(300);
ledPanel.Toggle(4);
using var dht = new Dht(dataPin: 4, DhtDevice.Dht22);
Console.WriteLine("Waiting for the sensor to response...");
while (true)
{
var temperature = await dht.GetTemperatureAsync(TemperatureUnit.Celsius, CancellationToken.None);
Console.WriteLine($"Temperature: {temperature:F1}\u00B0C");
var humidity = await dht.GetHumidityAsync(CancellationToken.None);
Console.WriteLine($"Humidity: {humidity:F1}%");
await Task.Delay(1000);
}
private static readonly int[] _inputs = { 18, 23, 24, 25 };
private static readonly int[] _outputs = { 10, 22, 27, 17 };
private static readonly char[,] _keyMap =
{
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
public static async Task<int> RunAsync()
{
using var keypad4x4 = new MatrixKeyboard(_inputs, _outputs, _keyMap);
while (true)
{
var key = await keypad4x4.ReadKeyAsync();
Console.WriteLine($"Key pressed: {key}");
}
}