Exemplo n.º 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);
 }
Exemplo n.º 2
0
        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));
            }
        }
Exemplo n.º 3
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>
        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");
                }
        }
Exemplo n.º 4
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");
                }
        }
Exemplo n.º 5
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...");
                }
            }
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            Heater heater = null;

            ConsoleEx.WriteLineWithDate("AquariumController is running");

            ConsoleEx.WriteLineWithDate("Setting up I2C...");
            I2cConnectionSettings settings = new I2cConnectionSettings(BUSID, I2CADDRESS);
            I2cDevice             device   = I2cDevice.Create(settings);

            ConsoleEx.WriteLineWithDate("Setting up UFire EC Probe...");
            Iot.Device.UFire.UFire_pH uFire_pH = new Iot.Device.UFire.UFire_pH(device);
            uFire_pH.UseTemperatureCompensation(true);

            ConsoleEx.WriteLineWithDate("Setting up MySql db....");
            MySqlConnection conn = new MySqlConnection(ConfigurationManager.AppSettings.Get("ConnectionString"));

            conn.Open();

            ConsoleEx.WriteLineWithDate("Setting up Heater....");
            heater = new Heater(conn);

            Timer saveTemperturTimer = Settings.SetupSaveInterval(conn, "TemperatureSaveInterval", Tempertur.SaveTempertur);
            Timer savePhTimer        = Settings.SetupSaveInterval(conn, "PHSaveInterval", Ph.SavePh);

            //read setting every 5 minute.
            AutoResetEvent saveTemperturAutoResetEvent = new AutoResetEvent(false);
            Timer          readSetupTimer = new Timer(Settings.ReadSetup, saveTemperturAutoResetEvent, 0, 5 * 60 * 1000);

            ConsoleEx.WriteLineWithDate("Setting up GpioController....");
            _Controller = new GpioController();
            _Controller.OpenPin(AIRPUMPPIN, PinMode.Output);

            ConsoleEx.WriteLineWithDate("Setting up Lcd1602....");
            using (Lcd1602 lcd = new Lcd1602(registerSelectPin: LCDRSPIN, enablePin: LCDENABLEPIN, dataPins: LCDDATA, shouldDispose: true))
            {
                LcdConsole console = new LcdConsole(lcd, "A00", false)
                {
                    LineFeedMode  = LineWrapMode.Wrap,
                    ScrollUpDelay = new TimeSpan(0, 0, 1)
                };

                SetCharacters.FishCharacters(lcd);
                SetCharacters.TemperatureCharacters(lcd);
                lcd.SetCursorPosition(0, 0);

                int  _fishCount     = 0;
                bool _revers        = false;
                int  _positionCount = 0;

                while (!Console.KeyAvailable)
                {
                    try
                    {
                        Tempertur.TemperturValue = Convert.ToDouble(uFire_pH.MeasureTemp()) + Tempertur.TemperturCalibrateOffSet;

                        Ph.PH = Math.Round(uFire_pH.MeasurepH(), 1);

                        string tempterturText = Math.Round(Tempertur.TemperturValue, 1, MidpointRounding.AwayFromZero).ToString() + (char)SetCharacters.TemperatureCharactersNumber;

                        string pHText = Ph.PH + "pH";

                        console.ReplaceLine(0, tempterturText + " " + pHText);

                        Animation.ShowFishOnLine2(console, ref _fishCount, ref _revers, ref _positionCount);

                        Heater.SetHeaterControlOnOff(conn, Tempertur.TemperturValue);
                        heater.HeaterOnOff(conn);

                        //Blink display if tempertur is over max tempertur
                        if (Tempertur.TemperturValue > Tempertur.TemperatureMax)
                        {
                            console.BlinkDisplay(1);
                        }


                        AirPump.AirPumpOnOff(conn, _Controller, AIRPUMPPIN);
                    }
#pragma warning disable CA1031 // Do not catch general exception types
                    catch (Exception ex)
                    {
                        ConsoleEx.WriteLineWithDate("Got an error: " + ex.Message + "StackTrace: " + ex.StackTrace);
                        if (ex.InnerException != null)
                        {
                            ConsoleEx.WriteLineWithDate("Error InnerException: " + ex.InnerException.Message);
                        }
                    }
                    finally
                    {
                        Thread.Sleep(1000);
                    }
#pragma warning restore CA1031 // Do not catch general exception types
                }

                console.Dispose();
            }

            saveTemperturTimer.Dispose();
            savePhTimer.Dispose();
            readSetupTimer.Dispose();

            conn.Close();
            conn.Dispose();

            _Controller.Dispose();
        }