Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new HD44780 LCD controller.
        /// </summary>
        /// <param name="size">The logical size of the LCD.</param>
        /// <param name="interface">The interface to use with the LCD.</param>
        public Hd44780(Size size, LcdInterface @interface)
        {
            Size       = size;
            _interface = @interface;

            Initialize(size.Height);
            _rowOffsets = InitializeRowOffsets(size.Height);
        }
Exemplo n.º 2
0
        private static (ITextDisplayDevice, IDisposable) Create(GpioController gpioController)
        {
            var lcdInterface = LcdInterface.CreateGpio(ToChipPin(29), ToChipPin(32),
                                                       new[] { ToChipPin(31), ToChipPin(33), ToChipPin(35), ToChipPin(37) },
                                                       controller: gpioController,
                                                       shouldDispose: false);
            var hd44780 = new Lcd1602(lcdInterface);

            return(new Sundew.TextView.Iot.Devices.Drivers.LcdTextDisplayDevice(hd44780, "A00"), hd44780);
        }
Exemplo n.º 3
0
 /// <summary>
 /// This method will use I2C commands to talk to the display. The display is expected to be at address 0x27 and accept 4 bit commands.
 /// This runs a full test suite against the display.
 /// </summary>
 static void UsingHd44780OverI2C()
 {
     using (I2cDevice i2CDevice = I2cDevice.Create(new I2cConnectionSettings(1, 0x27)))
     {
         LcdInterface lcdInterface = LcdInterface.CreateI2c(i2CDevice, false);
         using (Hd44780 hd44780 = new Lcd2004(lcdInterface))
         {
             hd44780.UnderlineCursorVisible = false;
             hd44780.BacklightOn            = true;
             hd44780.DisplayOn = true;
             hd44780.Clear();
             ExtendedSample.Test(hd44780);
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// This method will use I2C commands to talk to the display. The display is expected to be at address 0x27 and accept 4 bit commands.
        /// This runs a full test suite against the display.
        /// </summary>
        private static void UsingHd44780OverI2C()
        {
            using (I2cDevice i2CDevice = I2cDevice.Create(new I2cConnectionSettings(1, 0x27)))
            {
                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);
                }
            }
        }
Exemplo n.º 5
0
        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...");
                }
            }
        }