public PIManager() { i2CConnectionSettings = new I2cConnectionSettings(1, GrovePi.DefaultI2cAddress); grovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings)); try { i2cLcdDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x3E)); i2cRgbDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x62)); lcd = new LcdRgb1602(i2cLcdDevice, i2cRgbDevice); } catch (Exception e) { Console.WriteLine("Lcd device not found."); } Info = new List <string>(); greenPulse = 0; orangePulse = 0; redPulse = 0; grovePi.PinMode(GrovePort.DigitalPin4, PinMode.Output); grovePi.PinMode(GrovePort.DigitalPin3, PinMode.Output); grovePi.PinMode(GrovePort.DigitalPin2, PinMode.Output); }
public ActionResult <string> ShowText(string text) { //Connection to the Grove-LCD and RGB Backlight var i2cLcdDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x3E)); var i2cRgbDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x62)); var lcd = new LcdRgb1602(i2cLcdDevice, i2cRgbDevice); // Write text on Grove-LCD Backlight lcd.Write(text); // Change Backlightcolor lcd.SetBacklightColor(Color.Azure); return($"Succesfully printed text: {text}"); }
static void SetBacklightColorTest(LcdRgb1602 lcd) { Color[] colors = { Color.Red, Color.Green, Color.Blue, Color.Aqua, Color.Azure, Color.Brown, Color.Chocolate, Color.LemonChiffon, Color.Lime, Color.Tomato, Color.Yellow }; foreach (var color in colors) { lcd.Clear(); lcd.Write(color.Name); lcd.SetBacklightColor(color); System.Threading.Thread.Sleep(1000); } lcd.Clear(); lcd.SetBacklightColor(Color.White); }
public GrovePiService() { I2cConnectionSettings i2CConnectionSettings = new I2cConnectionSettings(1, GrovePi.DefaultI2cAddress); GrovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings)); // Lights KitchenLight = new Led(GrovePi, GrovePort.DigitalPin2); LivingRoomLight = new Led(GrovePi, GrovePort.DigitalPin3); BathroomLight = new Led(GrovePi, GrovePort.DigitalPin4); // Sensors TempHumid = new DhtSensor(GrovePi, GrovePort.DigitalPin8, DhtType.Dht11); // Display var i2cLcdDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x3E)); var i2cRgbDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x62)); Display = new LcdRgb1602(i2cLcdDevice, i2cRgbDevice); }
public static void Test() { Console.WriteLine("Starting..."); #if USEI2C var i2cDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x21)); var controller = new Mcp23008(i2cDevice); var lcd = new Lcd1602(registerSelectPin: 1, enablePin: 2, dataPins: new int[] { 3, 4, 5, 6 }, backlightPin: 7, controller: controller); #elif USERGB var i2cLcdDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x3E)); var i2cRgbDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x62)); var lcd = new LcdRgb1602(i2cLcdDevice, i2cRgbDevice); #else Hd44780 lcd = new Hd44780(new Size(20, 4), LcdInterface.CreateGpio(12, 26, new int[] { 16, 17, 18, 19, 20, 21, 22, 23 }, readWritePin: 13)); #endif using (lcd) { Console.WriteLine("Initialized"); Console.ReadLine(); TestPrompt("SetCursor", lcd, SetCursorTest); TestPrompt("Underline", lcd, l => l.UnderlineCursorVisible = true); lcd.UnderlineCursorVisible = false; TestPrompt("Walker", lcd, WalkerTest); CreateTensCharacters(lcd); TestPrompt("CharacterSet", lcd, CharacterSet); // Shifting TestPrompt("Autoshift", lcd, AutoShift); TestPrompt("DisplayLeft", lcd, l => ShiftDisplayTest(l, a => a.ShiftDisplayLeft())); TestPrompt("DisplayRight", lcd, l => ShiftDisplayTest(l, a => a.ShiftDisplayRight())); TestPrompt("CursorLeft", lcd, l => ShiftCursorTest(l, a => a.ShiftCursorLeft())); TestPrompt("CursorRight", lcd, l => ShiftCursorTest(l, a => a.ShiftCursorRight())); // Long string TestPrompt("Twenty", lcd, l => l.Write(Twenty)); TestPrompt("Fourty", lcd, l => l.Write(Fourty)); TestPrompt("Eighty", lcd, l => l.Write(Eighty)); TestPrompt("Twenty-", lcd, l => WriteFromEnd(l, Twenty)); TestPrompt("Fourty-", lcd, l => WriteFromEnd(l, Fourty)); TestPrompt("Eighty-", lcd, l => WriteFromEnd(l, Eighty)); TestPrompt("Wrap", lcd, l => l.Write(new string('*', 80) + ">>>>>")); TestPrompt("Perf", lcd, PerfTests); #if USERGB TestPrompt("Colors", lcd, SetBacklightColorTest); #endif // Shift display right lcd.Write("Hello .NET!"); try { int state = 0; Timer timer = new Timer(1000); timer.Elapsed += (o, e) => { lcd.SetCursorPosition(0, 1); lcd.Write(DateTime.Now.ToLongTimeString() + " "); if (state == 0) { state = 1; } else { lcd.ShiftDisplayRight(); state = 0; } }; timer.AutoReset = true; timer.Enabled = true; Console.ReadLine(); } finally { lcd.DisplayOn = false; lcd.BacklightOn = false; Console.WriteLine("Done..."); } } }