コード例 #1
0
 private void DisplayLcdText(string line1 = "No data", string line2 = "")
 {
     lcd.Clear();
     lcd.SetCursorPosition(0, 0);
     lcd.Write(line1);
     lcd.SetCursorPosition(0, 1);
     lcd.Write(line2);
 }
コード例 #2
0
 public void TestMethod1()
 {
     using (Lcd1602 lcd = new Lcd1602(new I2CMock("/dev/i2c-1", 0x27))) //0x27 address of LCD
     {
         Console.WriteLine("Init");
         lcd.Init();
         Console.WriteLine("Clear");
         lcd.Clear();
         Console.WriteLine("Hello");
         lcd.Write(0, 0, "Hello");
         Console.WriteLine("World!");
         lcd.Write(0, 1, "World!");
     }
 }
コード例 #3
0
 /// <summary>
 /// This sets up a 16x2 character LCD, directly connected to a set of GPIO pins, with a hardwired or no backlight and 4 Bit commands
 /// </summary>
 private static void UsingGpioPins()
 {
     using (Lcd1602 lcd = new Lcd1602(registerSelectPin: 22, enablePin: 17, dataPins: new int[] { 25, 24, 23, 18 }))
     {
         lcd.Clear();
         lcd.Write("Hello World");
     }
 }
コード例 #4
0
ファイル: CharacterLcd.Sample.cs プロジェクト: giegloop/iot-1
 /// <summary>
 /// This program will print `Hello World`
 /// </summary>
 /// <param name="args">Should be empty</param>
 static void Main(string[] args)
 {
     // Sets up a 16x2 character LCD with a hardwired or no backlight.
     using (Lcd1602 lcd = new Lcd1602(registerSelectPin: 22, enablePin: 17, dataPins: new int[] { 25, 24, 23, 18 }))
     {
         lcd.Clear();
         lcd.Write("Hello World");
     }
 }
コード例 #5
0
ファイル: CharacterLcd.Sample.cs プロジェクト: hhy5277/iot-1
 /// <summary>
 /// This program will print `Hello World`
 /// </summary>
 /// <param name="args">Should be empty</param>
 static void Main(string[] args)
 {
     // Sets up a 16x2 character LCD with a hardwired or no backlight.
     using (Lcd1602 lcd = new Lcd1602(registerSelect: 1, enable: 2, data: new int[] { 3, 4, 5, 6 }))
     {
         lcd.Clear();
         lcd.Write("Hello World");
     }
 }
コード例 #6
0
ファイル: CharacterLcd.Sample.cs プロジェクト: giegloop/iot-1
        /// <summary>
        /// This method will use an mcp gpio extender to connect to the LCM display.
        /// This has been tested on the CrowPi lcd display.
        /// </summary>
        static void UsingMcp()
        {
            UnixI2cDevice i2CDevice = new UnixI2cDevice(new I2cConnectionSettings(1, 0x21));
            Mcp23008      mcpDevice = new Mcp23008(i2CDevice);

            int[] dataPins          = { 3, 4, 5, 6 };
            int   registerSelectPin = 1;
            int   enablePin         = 2;
            int   backlight         = 7;

            using (mcpDevice)
                using (Lcd1602 lcd = new Lcd1602(registerSelectPin, enablePin, dataPins, backlight, controller: mcpDevice))
                {
                    lcd.Clear();

                    lcd.Write("Hello World");
                    lcd.SetCursorPosition(0, 1);
                    lcd.Write(".NET Core");
                }
        }
コード例 #7
0
        /// <summary>
        /// This method will use an mcp gpio extender to connect to the LCM display.
        /// This has been tested on the CrowPi lcd display.
        /// </summary>
        private static void UsingMcp()
        {
            I2cDevice i2CDevice = I2cDevice.Create(new I2cConnectionSettings(1, 0x21));
            Mcp23008  driver    = new Mcp23008(i2CDevice);

            int[] dataPins          = { 3, 4, 5, 6 };
            int   registerSelectPin = 1;
            int   enablePin         = 2;
            int   backlight         = 7;

            using (driver)
                using (Lcd1602 lcd = new Lcd1602(registerSelectPin, enablePin, dataPins, backlight, controller: new GpioController(PinNumberingScheme.Logical, driver)))
                {
                    lcd.Clear();

                    lcd.Write("Hello World");
                    lcd.SetCursorPosition(0, 1);
                    lcd.Write(".NET Core");
                }
        }
コード例 #8
0
        static void Main(string[] args)
        {
            Lcd1602 lcd = new Lcd1602(I2cDevice.Create(new I2cConnectionSettings(1, DefaultLcdAddress)))
            {
                DisplayOn             = true,
                BacklightOn           = true,
                BlinkingCursorVisible = true,
                Increment             = true,
            };

            lcd.Write("Hello, World!");
        }
コード例 #9
0
ファイル: LcdDisplay.cs プロジェクト: ghhv/have-your-pi
        public async Task DisplayText(string text)
        {
            int    screenWidth = 16;
            string padding     = new string(' ', screenWidth);
            string paddedText  = $"{padding}{text}{padding}";

            _lcd.Clear();
            for (int i = 0; i <= (text.Length + screenWidth); i++)
            {
                string frame = paddedText.Substring(i, screenWidth);
                _lcd.SetCursorPosition(0, 0);
                _lcd.Write(frame);
                await Task.Delay(TimeSpan.FromMilliseconds(250));
            }
        }
コード例 #10
0
        static void Test1602()
        {
            using (Lcd1602 lcd = new Lcd1602(new I2C("/dev/i2c-1", 0x27))) //0x27 address of LCD
            {
                lcd.Init();
                lcd.Clear();

                var screenWidth = 16;
                var message     = "Hello Krysia,  how are you today?";
                var text        = message.PadLeft(message.Length + screenWidth).PadRight(message.Length + 2 * screenWidth);

                for (var i = 0; i < text.Length - screenWidth + 1; i++)
                {
                    lcd.Write(0, 0, text.Substring(i, screenWidth));
                    Thread.Sleep(250);
                }
            }
        }
コード例 #11
0
        public static void SampleEntryPoint()
        {
            Console.WriteLine("Starting...");
            // for PCF8574T i2c addresses can be between 0x27 and 0x20 depending on bridged solder jumpers
            // for PCF8574AT i2c addresses can be between 0x3f and 0x38 depending on bridged solder jumpers
            var i2cDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x27));
            var driver    = new Pcf8574(i2cDevice);
            var lcd       = new Lcd1602(registerSelectPin: 0, enablePin: 2, dataPins: new int[] { 4, 5, 6, 7 }, backlightPin: 3, readWritePin: 1, controller: new GpioController(PinNumberingScheme.Logical, driver));

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