예제 #1
0
        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);
                }
            }
        }
예제 #2
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);
            }
        }
예제 #3
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;
 }
예제 #4
0
        private static void ShiftDisplayTest(Hd44780 lcd, Action <Hd44780> action)
        {
            Size size = lcd.Size;

            lcd.Write(Eighty.Substring(0, size.Height * size.Width));
            ShiftTest(lcd, action);
        }
예제 #5
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);
            }
        }
예제 #6
0
        private static void SetBacklightColorTest(Hd44780 lcd)
        {
            var colorLcd = lcd as LcdRgb;

            if (colorLcd == null)
            {
                Console.WriteLine("Color backlight not supported");
                return;
            }

            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);

                colorLcd.SetBacklightColor(color);
                System.Threading.Thread.Sleep(1000);
            }

            lcd.Clear();
            colorLcd.SetBacklightColor(Color.White);
        }
예제 #7
0
        private static void AutoShift(Hd44780 lcd)
        {
            lcd.AutoShift = true;
            Size size = lcd.Size;

            lcd.Write(Eighty.Substring(0, size.Width + size.Width / 2));
            lcd.AutoShift = false;
        }
예제 #8
0
        private static void PerfTests(Hd44780 lcd)
        {
            string    stars     = new string('*', 80);
            Stopwatch stopwatch = Stopwatch.StartNew();

            lcd.Clear();
            for (int i = 0; i < 25; i++)
            {
                lcd.Write(Eighty);
                lcd.Write(stars);
            }

            lcd.Clear();
            stopwatch.Stop();
            string result = $"Elapsed ms: {stopwatch.ElapsedMilliseconds}";

            lcd.Write(result);
            Console.WriteLine(result);
        }
예제 #9
0
 static void DisplayAndBackLightOnOff(Hd44780 lcd)
 {
     lcd.Clear();
     lcd.Write("This is some text");
     lcd.DisplayOn = false;
     Thread.Sleep(1000);
     lcd.DisplayOn   = true;
     lcd.BacklightOn = false;
     Thread.Sleep(1000);
     lcd.BacklightOn = true;
 }
예제 #10
0
        static void TestPrompt(string test, Hd44780 lcd, Action <Hd44780> action)
        {
            string prompt = $"Test {test}:";

            lcd.Clear();
            lcd.Write(prompt);
            lcd.BlinkingCursorVisible = true;
            Console.Write(prompt);
            Console.ReadLine();
            lcd.BlinkingCursorVisible = false;
            lcd.Clear();
            action(lcd);
            Console.Write("Test Complete:");
            Console.ReadLine();
            lcd.Clear();
        }
예제 #11
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...");
                }
            }
        }