Ejemplo n.º 1
0
 /// <summary>
 /// A small test that shows something useful. It may not work optimally due to wrong character mappings if the month names contain non-ascii characters.
 /// </summary>
 static void TestClock(Hd44780 lcd)
 {
     using (System.Timers.Timer timer = new System.Timers.Timer(100))
     {
         object myLock = new object();
         timer.Elapsed += (o, e) =>
         {
             // The callback may be executed in parallel several times, but the display component is not reentrant!
             if (Monitor.TryEnter(myLock))
             {
                 var now = DateTime.Now;
                 lcd.SetCursorPosition(0, 0);
                 lcd.Write(String.Format(CultureInfo.CurrentCulture, "{0:dddd}", now));
                 lcd.SetCursorPosition(0, 1);
                 lcd.Write(String.Format(CultureInfo.CurrentCulture, "{0:M} {0:yyyy}", now, now));
                 lcd.SetCursorPosition(0, 2);
                 lcd.Write("It is now ");
                 lcd.SetCursorPosition(0, 3);
                 lcd.Write(String.Format(CultureInfo.CurrentCulture, "{0}", now.ToLongTimeString()));
                 Monitor.Exit(myLock);
             }
         };
         timer.AutoReset = true;
         timer.Enabled   = true;
         Console.ReadLine();
     }
 }
Ejemplo n.º 2
0
        private static void SetCursorTest(Hd44780 lcd)
        {
            Size size   = lcd.Size;
            int  number = 0;

            for (int i = 0; i < size.Height; i++)
            {
                lcd.SetCursorPosition(0, i);
                lcd.Write($"{number++}");
                lcd.SetCursorPosition(size.Width - 1, i);
                lcd.Write($"{number++}");
            }
        }
Ejemplo n.º 3
0
        private static void CharacterSet(Hd44780 lcd)
        {
            StringBuilder sb = new StringBuilder(256);

            for (int i = 0; i < 256; i++)
            {
                sb.Append((char)i);
            }

            int  character = 0;
            int  line      = 0;
            Size size      = lcd.Size;

            while (character < 256)
            {
                lcd.SetCursorPosition(0, line);
                lcd.Write(sb.ToString(character, Math.Min(size.Width, 256 - character)));
                line++;
                character += size.Width;
                if (line >= size.Height)
                {
                    line = 0;
                    System.Threading.Thread.Sleep(1000);
                }
            }
        }
Ejemplo n.º 4
0
        private static void WalkerTest(Hd44780 lcd)
        {
            CreateWalkCharacters(lcd);
            string walkOne = new string('\x8', lcd.Size.Width);
            string walkTwo = new string('\x9', lcd.Size.Width);

            for (int i = 0; i < 5; i++)
            {
                lcd.SetCursorPosition(0, 0);
                lcd.Write(walkOne);
                System.Threading.Thread.Sleep(500);
                lcd.SetCursorPosition(0, 0);
                lcd.Write(walkTwo);
                System.Threading.Thread.Sleep(500);
            }
        }
Ejemplo n.º 5
0
 private static void WriteFromEnd(Hd44780 lcd, string value)
 {
     lcd.Increment = false;
     lcd.SetCursorPosition(lcd.Size.Width - 1, lcd.Size.Height - 1);
     lcd.Write(value);
     lcd.Increment = true;
 }
Ejemplo n.º 6
0
        static async Task App()
        {
            var board = await ConnectionService.Instance.GetFirstDeviceAsync();

            await board.ConnectAsync();

            // configure the native parallel interface with the pins we're using
            board.ParallelInterface.RegisterSelectPin = board.Pins[0];
            board.ParallelInterface.ReadWritePin      = board.Pins[1];
            board.ParallelInterface.EnablePin         = board.Pins[2];
            board.ParallelInterface.DataBus.Add(board.Pins[3]);
            board.ParallelInterface.DataBus.Add(board.Pins[4]);
            board.ParallelInterface.DataBus.Add(board.Pins[5]);
            board.ParallelInterface.DataBus.Add(board.Pins[6]);
            board.ParallelInterface.DataBus.Add(board.Pins[7]);
            board.ParallelInterface.DataBus.Add(board.Pins[8]);
            board.ParallelInterface.DataBus.Add(board.Pins[9]);
            board.ParallelInterface.DataBus.Add(board.Pins[10]);

            var display = new Hd44780(board.ParallelInterface, 16, 2);
            await display.WriteLine("The time is:").ConfigureAwait(false);

            while (true)
            {
                await display.Write(DateTime.Now.ToLongTimeString()).ConfigureAwait(false);

                await display.SetCursorPosition(0, 1).ConfigureAwait(false);

                await Task.Delay(1000).ConfigureAwait(false);
            }
        }
Ejemplo n.º 7
0
        public static void Test()
        {
            Console.WriteLine("Starting...");

#if USEI2C
            var i2cDevice  = new UnixI2cDevice(new I2cConnectionSettings(busId: 1, deviceAddress: 0x21));
            var controller = new Mcp23008Adapter(new Mcp23008(i2cDevice));
            var lcd        = new Hd44780(registerSelect: 1, enable: 2, data: new int[] { 3, 4, 5, 6 }, size: new Size(16, 2), backlight: 7, controller: controller);
#else
            Hd44780 lcd = new Hd44780(12, 26, new int[] { 16, 17, 18, 19, 20, 21, 22, 23 }, new Size(20, 4), readWrite: 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);

                // 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...");
                }
            }
        }