Exemplo n.º 1
0
        public static void Run(string[] args)
        {
            Console.WriteLine("Nusbio initialization");
            var serialNumber = Nusbio.Detect();

            if (serialNumber == null) // Detect the first Nusbio available
            {
                Console.WriteLine("Nusbio not detected");
                return;
            }

            using (var nusbio = new Nusbio(serialNumber))
            {
                Cls(nusbio);

                int counter = 0;
                _machineInfo = new MachineInfo();
                var secondTimeOut = new TimeOut(1000);
                _liquidCrystal = new LiquidCrystal(nusbio, rs: 0, enable: 1, d0: 2, d1: 3, d2: 4, d3: 5);

                _liquidCrystal.Begin(16, 2);
                _liquidCrystal.Clear();

                while (nusbio.Loop())
                {
                    if (secondTimeOut.IsTimeOut())
                    {
                        counter++;
                        DisplayTime(_liquidCrystal);
                        if (counter % 5 == 0)
                        {
                            LiquidCrystalDemo.NusbioRocks(_liquidCrystal);
                        }
                        if (counter % 8 == 0)
                        {
                            LiquidCrystalDemo.ProgressBarDemo(_liquidCrystal);
                        }
                    }

                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.D)
                        {
                            DisplaySpeedTest(_liquidCrystal);
                            _liquidCrystal.Clear();
                        }
                        if (k == ConsoleKey.A)
                        {
                            LiquidCrystalDemo.ApiDemo(_liquidCrystal);
                            _liquidCrystal.Clear();
                        }
                        if (k == ConsoleKey.R)
                        {
                            LiquidCrystalDemo.NusbioRocks(_liquidCrystal);
                            _liquidCrystal.Clear();
                        }
                        if (k == ConsoleKey.C)
                        {
                            CustomCharDemo(_liquidCrystal);
                            _liquidCrystal.Clear();
                        }

                        if (k == ConsoleKey.F)
                        {
                            Cls(nusbio);
                        }
                        if (k == ConsoleKey.Q)
                        {
                            _liquidCrystal.Clear();
                            break;
                        }
                        Cls(nusbio);
                    }
                }
            }

            Console.Clear();
        }
Exemplo n.º 2
0
        public static void Run(string[] args)
        {
            Console.WriteLine("Nusbio initialization");
            var serialNumber = Nusbio.Detect();

            if (serialNumber == null) // Detect the first Nusbio available
            {
                Console.WriteLine("Nusbio not detected");
                return;
            }

            // The PCF8574 has limited speed
            Nusbio.BaudRate = LiquidCrystal_I2C_PCF8574.MAX_BAUD_RATE;

            using (var nusbio = new Nusbio(serialNumber))
            {
                Console.WriteLine("LCD i2c Initialization");

                // I2C LCD directly plugged into Nusbio
                var sda = NusbioGpio.Gpio7;
                var scl = NusbioGpio.Gpio6;

                if (nusbio.Type == NusbioType.NusbioType1_Light)
                {
                    sda = NusbioGpio.Gpio7; // Directly connected into Nusbio
                    scl = NusbioGpio.Gpio6;
                }

                var maxColumn = 16;
                var maxRow    = 2;

                var lcdI2C = LiquidCrystal_I2C_PCF8574.Detect(nusbio, maxColumn, maxRow, sda, scl);
                if (lcdI2C == null)
                {
                    Console.WriteLine("Hit any key to continue");
                    Console.ReadKey();
                    return;
                }

                lcdI2C.Backlight();
                lcdI2C.Print(0, 0, "Hi!");

                /// This temperature sensor is used to also demo how to connect
                /// multiple devices directly into Nusbio by using the Nsubio Expander Extension
                /// https://squareup.com/market/madeintheusb-dot-net/ex-expander
                MCP9808_TemperatureSensor _MCP9808_TemperatureSensor = null;
                #if INCLUDE_TemperatureSensorMCP0908_InDemo
                _MCP9808_TemperatureSensor = InitializeI2CAdafruitTemperatureSensorMCP0908_ClockGpio1_DataGpio0(nusbio);
                #endif
                var timeOut = new TimeOut(1000);

                Cls(nusbio);

                while (nusbio.Loop())
                {
                    if (_MCP9808_TemperatureSensor != null && timeOut.IsTimeOut())
                    {
                        lcdI2C.Print(0, 0, DateTime.Now.ToString("T"));
                        lcdI2C.Print(0, 1, "Temp {0:00}C {1:00}F", _MCP9808_TemperatureSensor.GetTemperature(TemperatureType.Celsius), _MCP9808_TemperatureSensor.GetTemperature(TemperatureType.Fahrenheit));
                    }

                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.Q)
                        {
                            nusbio.ExitLoop();
                        }
                        if (k == ConsoleKey.P)
                        {
                            PerformanceTest(lcdI2C);
                            lcdI2C.Clear();
                        }
                        if (k == ConsoleKey.C)
                        {
                            Cls(nusbio);
                            lcdI2C.Clear();
                        }
                        if (k == ConsoleKey.A)
                        {
                            LiquidCrystalDemo.ApiDemo(lcdI2C);
                            lcdI2C.Clear();
                        }
                        if (k == ConsoleKey.R)
                        {
                            LiquidCrystalDemo.NusbioRocks(lcdI2C, 333);
                            lcdI2C.Clear();
                        }
                        if (k == ConsoleKey.H)
                        {
                            LiquidCrystalDemo.CustomCharDemo(lcdI2C);
                        }
                        if (k == ConsoleKey.T)
                        {
                            LiquidCrystalDemo.ProgressBarDemo(lcdI2C);
                            LiquidCrystalDemo.NusbioRocksOrWhat(lcdI2C);
                        }
                        Cls(nusbio);
                    }
                }
            }
            Console.Clear();
        }