/// <summary> /// This sets up a 16x2 character LCD, directly connected to a set of GPIO pins, with a hardwired or no backlight and 4 Bit commands /// </summary> private static void UsingGpioPins() { using (Lcd1602 lcd = new Lcd1602(registerSelectPin: 22, enablePin: 17, dataPins: new int[] { 25, 24, 23, 18 })) { lcd.Clear(); lcd.Write("Hello World"); } }
private void DisplayLcdText(string line1 = "No data", string line2 = "") { lcd.Clear(); lcd.SetCursorPosition(0, 0); lcd.Write(line1); lcd.SetCursorPosition(0, 1); lcd.Write(line2); }
/// <summary> /// This program will print `Hello World` /// </summary> /// <param name="args">Should be empty</param> static void Main(string[] args) { // Sets up a 16x2 character LCD with a hardwired or no backlight. using (Lcd1602 lcd = new Lcd1602(registerSelectPin: 22, enablePin: 17, dataPins: new int[] { 25, 24, 23, 18 })) { lcd.Clear(); lcd.Write("Hello World"); } }
/// <summary> /// This program will print `Hello World` /// </summary> /// <param name="args">Should be empty</param> static void Main(string[] args) { // Sets up a 16x2 character LCD with a hardwired or no backlight. using (Lcd1602 lcd = new Lcd1602(registerSelect: 1, enable: 2, data: new int[] { 3, 4, 5, 6 })) { lcd.Clear(); lcd.Write("Hello World"); } }
public void TestMethod1() { using (Lcd1602 lcd = new Lcd1602(new I2CMock("/dev/i2c-1", 0x27))) //0x27 address of LCD { Console.WriteLine("Init"); lcd.Init(); Console.WriteLine("Clear"); lcd.Clear(); Console.WriteLine("Hello"); lcd.Write(0, 0, "Hello"); Console.WriteLine("World!"); lcd.Write(0, 1, "World!"); } }
public async Task DisplayText(string text) { int screenWidth = 16; string padding = new string(' ', screenWidth); string paddedText = $"{padding}{text}{padding}"; _lcd.Clear(); for (int i = 0; i <= (text.Length + screenWidth); i++) { string frame = paddedText.Substring(i, screenWidth); _lcd.SetCursorPosition(0, 0); _lcd.Write(frame); await Task.Delay(TimeSpan.FromMilliseconds(250)); } }
public CharacterDisplay(ArduinoBoard board) { _controller = board.CreateGpioController(); _display = new Lcd1602(8, 9, new int[] { 4, 5, 6, 7 }, -1, 1.0f, -1, _controller); _display.BlinkingCursorVisible = false; _display.UnderlineCursorVisible = false; _display.Clear(); _textController = new LcdConsole(_display, "SplC780", false); _textController.Clear(); LcdCharacterEncodingFactory f = new LcdCharacterEncodingFactory(); var cultureEncoding = f.Create(CultureInfo.CurrentCulture, "SplC780", '?', _display.NumberOfCustomCharactersSupported); _textController.LoadEncoding(cultureEncoding); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { using I2cDevice i2c = I2cDevice.Create(new I2cConnectionSettings(1, 0x27)); using Pcf8574 driver = new Pcf8574(i2c); lcd = new Lcd1602(registerSelectPin: 0, enablePin: 2, dataPins: new int[] { 4, 5, 6, 7 }, backlightPin: 3, backlightBrightness: 1f, readWritePin: 1, controller: new GpioController(PinNumberingScheme.Logical, driver)); while (!stoppingToken.IsCancellationRequested) { TemperatureDto interiorTemp = await _temperatureReadingService.GetLatestInteriorReadingAsync(); lcd.Clear(); string output = string.Empty; DisplayLcdText( interiorTemp != null ? $"In: {interiorTemp.Fahrenheit.ToString()}F {interiorTemp.Celsius.ToString()}C" : "No Data", DateTime.Now.ToString("ddd MM/dd HH:mm") ); await Task.Delay(TimeSpan.FromSeconds(DelaySeconds), stoppingToken); TemperatureDto minInteriorTemp = await _temperatureReadingService.GetMinInteriorReadingAsync(); TemperatureDto maxInteriorTemp = await _temperatureReadingService.GetMaxInteriorReadingAsync(); output = string.Empty; DisplayLcdText( minInteriorTemp != null ? $"Min: {minInteriorTemp.Fahrenheit.ToString()}F {minInteriorTemp.Celsius.ToString()}C" : string.Empty, maxInteriorTemp != null ? $"Max: {maxInteriorTemp.Fahrenheit.ToString()}F {maxInteriorTemp.Celsius.ToString()}C" : string.Empty ); await Task.Delay(TimeSpan.FromSeconds(DelaySeconds), stoppingToken); } }
static void Test1602() { using (Lcd1602 lcd = new Lcd1602(new I2C("/dev/i2c-1", 0x27))) //0x27 address of LCD { lcd.Init(); lcd.Clear(); var screenWidth = 16; var message = "Hello Krysia, how are you today?"; var text = message.PadLeft(message.Length + screenWidth).PadRight(message.Length + 2 * screenWidth); for (var i = 0; i < text.Length - screenWidth + 1; i++) { lcd.Write(0, 0, text.Substring(i, screenWidth)); Thread.Sleep(250); } } }
/// <summary> /// This method will use an mcp gpio extender to connect to the LCM display. /// This has been tested on the CrowPi lcd display. /// </summary> static void UsingMcp() { UnixI2cDevice i2CDevice = new UnixI2cDevice(new I2cConnectionSettings(1, 0x21)); Mcp23008 mcpDevice = new Mcp23008(i2CDevice); int[] dataPins = { 3, 4, 5, 6 }; int registerSelectPin = 1; int enablePin = 2; int backlight = 7; using (mcpDevice) using (Lcd1602 lcd = new Lcd1602(registerSelectPin, enablePin, dataPins, backlight, controller: mcpDevice)) { lcd.Clear(); lcd.Write("Hello World"); lcd.SetCursorPosition(0, 1); lcd.Write(".NET Core"); } }
/// <summary> /// This method will use an mcp gpio extender to connect to the LCM display. /// This has been tested on the CrowPi lcd display. /// </summary> private static void UsingMcp() { I2cDevice i2CDevice = I2cDevice.Create(new I2cConnectionSettings(1, 0x21)); Mcp23008 driver = new Mcp23008(i2CDevice); int[] dataPins = { 3, 4, 5, 6 }; int registerSelectPin = 1; int enablePin = 2; int backlight = 7; using (driver) using (Lcd1602 lcd = new Lcd1602(registerSelectPin, enablePin, dataPins, backlight, controller: new GpioController(PinNumberingScheme.Logical, driver))) { lcd.Clear(); lcd.Write("Hello World"); lcd.SetCursorPosition(0, 1); lcd.Write(".NET Core"); } }