public static void WriteToLcd() { Console.WriteLine("writing to the lcd"); const ConnectorPin sdaPin = ConnectorPin.P1Pin03; const ConnectorPin sclPin = ConnectorPin.P1Pin05; using (var driver = new I2cDriver(sdaPin.ToProcessor(), sclPin.ToProcessor())) { var deviceConnection = new Mcp23017I2cConnection(driver.Connect(0x20)); Console.WriteLine("Connected"); // turn on LCD backlight (on/off/on) deviceConnection.SetDirection(Mcp23017Pin.A0, Mcp23017PinDirection.Output); deviceConnection.SetPinStatus(Mcp23017Pin.A0, true); Thread.Sleep(500); // wait deviceConnection.SetPinStatus(Mcp23017Pin.A0, false); Thread.Sleep(500); // wait deviceConnection.SetPinStatus(Mcp23017Pin.A0, true); } // light is on, let's write var settings = new Hd44780LcdConnectionSettings { ScreenWidth = 16, ScreenHeight = 2 }; settings.Encoding = Encoding.ASCII; using (Hd44780Configuration configuration = Hd44780Configuration.LoadGpioConfiguration()) using (var connection = new Hd44780LcdConnection(settings, configuration.Pins)) { // connection.SetCustomCharacter(1, new byte[] { 0x0, 0x0, 0x04, 0xe, 0x1f, 0x0, 0x0 }); // connection.SetCustomCharacter(2, new byte[] { 0x0, 0x0, 0x1f, 0xe, 0x04, 0x0, 0x0 }); connection.Clear(); connection.WriteLine("Pi & Bash>_"); Thread.Sleep(750); connection.WriteLine("Test"); Thread.Sleep(750); connection.WriteLine("Thank You"); Thread.Sleep(750); connection.WriteLine("more text"); Thread.Sleep(750); connection.WriteLine("and another bit"); Thread.Sleep(2000); } }
public static void TurnOnGreenLed() { const ConnectorPin sdaPin = ConnectorPin.P1Pin03; const ConnectorPin sclPin = ConnectorPin.P1Pin05; const Mcp23017Pin ledGreen = Mcp23017Pin.B0; using (var driver = new I2cDriver(sdaPin.ToProcessor(), sclPin.ToProcessor())) { var deviceConnection = new Mcp23017I2cConnection(driver.Connect(0x20)); Console.WriteLine("Connected"); deviceConnection.SetDirection(ledGreen, Mcp23017PinDirection.Output); // green light off deviceConnection.SetPinStatus(ledGreen, true); System.Threading.Thread.Sleep(1000); // wait a sec deviceConnection.SetPinStatus(ledGreen, false); } }
/// <summary> /// Writes the value of the pin. /// </summary> /// <param name="state">if set to <c>true</c>, pin is set to high state.</param> public void Write(bool state) { connection.SetPinStatus(pin, state); }
public void SetBacklight(bool enabled) { deviceConnection.SetPinStatus(Mcp23017Pin.A0, enabled); }