-
Notifications
You must be signed in to change notification settings - Fork 625
Expand file tree
/
Copy pathProgram.cs
More file actions
113 lines (101 loc) · 3.54 KB
/
Program.cs
File metadata and controls
113 lines (101 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Device.Gpio;
using System.Device.I2c;
using System.Device.Spi;
using System.Drawing;
using CharacterLcd.Samples;
using Iot.Device.Arduino;
using Iot.Device.Mcp23xxx;
using Iot.Device.CharacterLcd;
using Iot.Device.CharacterLcd.Samples;
using Iot.Device.Multiplexing;
// Choose the right setup for your display:
// UsingGpioPins();
// UsingMcp();
// UsingGroveRgbDisplay();
// UsingHd44780OverI2C();
// UsingHd44780OverI2CAndArduino();
// UsingAip31068Lcd();
UsingShiftRegister();
void UsingGpioPins()
{
using Lcd1602 lcd = new Lcd1602(registerSelectPin: 22, enablePin: 17, dataPins: new int[] { 25, 24, 23, 18 });
lcd.Clear();
lcd.Write("Hello World");
}
void UsingMcp()
{
using I2cDevice i2cDevice = I2cDevice.Create(new I2cConnectionSettings(1, 0x21));
using Mcp23008 driver = new(i2cDevice);
int[] dataPins = { 3, 4, 5, 6 };
int registerSelectPin = 1;
int enablePin = 2;
int backlight = 7;
using Lcd1602 lcd = new Lcd1602(registerSelectPin, enablePin, dataPins, backlight, controller: new GpioController(driver));
lcd.Clear();
lcd.Write("Hello World");
lcd.SetCursorPosition(0, 1);
lcd.Write(".NET Core");
}
void UsingHd44780OverI2C()
{
using I2cDevice i2cDevice = I2cDevice.Create(new I2cConnectionSettings(1, 0x27));
using LcdInterface lcdInterface = LcdInterface.CreateI2c(i2cDevice, false);
using Hd44780 hd44780 = new Lcd2004(lcdInterface);
hd44780.UnderlineCursorVisible = false;
hd44780.BacklightOn = true;
hd44780.DisplayOn = true;
hd44780.Clear();
Console.WriteLine("Display initialized. Press Enter to start tests.");
Console.ReadLine();
LcdConsoleSamples.WriteTest(hd44780);
ExtendedSample.Test(hd44780);
}
void UsingGroveRgbDisplay()
{
var i2cLcdDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x3E));
var i2cRgbDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x62));
using LcdRgb lcd = new LcdRgb(new Size(16, 2), i2cLcdDevice, i2cRgbDevice);
{
lcd.Write("Hello World!");
lcd.SetBacklightColor(Color.Azure);
}
}
void UsingHd44780OverI2CAndArduino()
{
using ArduinoBoard arduino = new ArduinoBoard("COM3", 115200);
using I2cDevice i2cDevice = arduino.CreateI2cDevice(new I2cConnectionSettings(0, 0x27));
using LcdInterface lcdInterface = LcdInterface.CreateI2c(i2cDevice, false);
using Hd44780 hd44780 = new Lcd2004(lcdInterface);
hd44780.UnderlineCursorVisible = false;
hd44780.BacklightOn = true;
hd44780.DisplayOn = true;
hd44780.Clear();
Console.WriteLine("Display initialized. Press Enter to start tests.");
Console.ReadLine();
LargeValueSample.LargeValueDemo(hd44780);
LcdConsoleSamples.WriteTest(hd44780);
ExtendedSample.Test(hd44780);
}
void UsingAip31068Lcd()
{
Aip31068Sample.Run();
}
void UsingShiftRegister()
{
int registerSelectPin = 1;
int enablePin = 2;
int[] dataPins = new int[] { 6, 5, 4, 3 };
int backlightPin = 7;
// Gpio
using ShiftRegister sr = new(ShiftRegisterPinMapping.Minimal, 8);
// Spi
// using SpiDevice spiDevice = SpiDevice.Create(new(0, 0));
// using ShiftRegister sr = new(spiDevice, 8);
using LcdInterface lcdInterface = LcdInterface.CreateFromShiftRegister(registerSelectPin, enablePin, dataPins, backlightPin, sr);
using Lcd1602 lcd = new(lcdInterface);
lcd.Clear();
lcd.Write("Hello World");
}