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

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

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

                var _4DIGITS7SEGMENTS_ADDR = 0x70 + 2;
                var clockPin   = NusbioGpio.Gpio0;             // White
                var dataOutPin = NusbioGpio.Gpio1;             // Green
                _4digits = new _4Digits7Segments(nusbio, dataOutPin, clockPin);
                _4digits.Begin(_4DIGITS7SEGMENTS_ADDR);
                _4digits.Clear(true);

                var oneSecondTimeOut = new TimeOut(1000);

                while (nusbio.Loop())
                {
                    if (oneSecondTimeOut.IsTimeOut())  // Make the colon blink at a 1 second rate

                    {
                        var t = DateTime.Now;

                        _4digits.Clear();
                        _4digits.Write(string.Format("{0}{1}", t.Minute.ToString("00"), t.Second.ToString("00")));

                        //if(twoSecondTimeOut.Counter % 2 == 0)
                        //    _4digits.Write(string.Format("{0}{1}", t.Minute.ToString("00"), t.Second.ToString("00")));
                        //else
                        //    _4digits.Write(string.Format("{0}{1}", t.Hour.ToString("00"), t.Minute.ToString("00")));

                        _4digits.WriteDisplay();
                        _4digits.DrawColon(!_4digits.ColonOn);
                    }

                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.D1)
                        {
                            Demo1();
                        }
                        if (k == ConsoleKey.D2)
                        {
                            Demo1To100();
                        }
                        if (k == ConsoleKey.D3)
                        {
                            DemoScrollNumber();
                        }
                        if (k == ConsoleKey.D4)
                        {
                            Demo1To10000();
                        }
                        if (k == ConsoleKey.C)
                        {
                            Cls(nusbio);
                            _4digits.Clear(true);
                        }
                        if (k == ConsoleKey.Q)
                        {
                            _4digits.Clear(true);
                            break;
                        }
                        Cls(nusbio);
                    }
                }
            }
            Console.Clear();
        }
Beispiel #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;
            }

            var clockPin   = NusbioGpio.None;
            var dataOutPin = NusbioGpio.None;
            var useAdafruitI2CAdapterForNusbio = false;

            if (useAdafruitI2CAdapterForNusbio)
            {
                clockPin   = NusbioGpio.Gpio1; // Clock should be zero, but on the Adafruit MCP9808 SCL and SDA are inversed compared to the Adafruit LED matrix
                dataOutPin = NusbioGpio.Gpio0;
            }
            else
            {
                clockPin   = NusbioGpio.Gpio0;
                dataOutPin = NusbioGpio.Gpio1;
            }

            using (var nusbio = new Nusbio(serialNumber))
            {
                _MCP9808_TemperatureSensor = new MCP9808_TemperatureSensor(nusbio, dataOutPin, clockPin);
                if (!_MCP9808_TemperatureSensor.Begin())
                {
                    Console.WriteLine("MCP9808 not detected on I2C bus. Hit any key to retry");
                    var kk = Console.ReadKey();
                    if (!_MCP9808_TemperatureSensor.Begin())
                    {
                        return;
                    }
                }

                Cls(nusbio);

                var everySecond = new TimeOut(1000);

                while (nusbio.Loop())
                {
                    if (everySecond.IsTimeOut())
                    {
                        double celsius = 0;
                        for (var i = 0; i < 3; i++)
                        {
                            celsius = _MCP9808_TemperatureSensor.GetTemperature(TemperatureType.Celsius);
                        }

                        ConsoleEx.WriteLine(1, 2,
                                            string.Format("Temperature Celsius:{0:000.00}, Fahrenheit:{1:000.00}, Kelvin:{2:00000.00}",
                                                          celsius,
                                                          _MCP9808_TemperatureSensor.CelsiusToFahrenheit(celsius),
                                                          _MCP9808_TemperatureSensor.CelsiusToKelvin(celsius)
                                                          ), ConsoleColor.Cyan);
                    }
                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.T)
                        {
                            Cls(nusbio);
                        }
                        if (k == ConsoleKey.D0)
                        {
                            Cls(nusbio);
                        }
                        if (k == ConsoleKey.C)
                        {
                            Cls(nusbio);
                        }
                        if (k == ConsoleKey.Q)
                        {
                            break;
                        }
                        Cls(nusbio);
                    }
                }
            }
            Console.Clear();
        }
Beispiel #3
0
        private static void FadeInOutLEDWithGpioAnd100mfCapacitorResistorTransistor(Nusbio nusbio, NusbioGpio regLedGpio, NusbioGpio blueLedGpio)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Fade In Out LED With Gpio With Capacitor/Resistor/Transistor");
            ConsoleEx.WriteMenu(-1, 4, "Q)uit");

            const int wait                     = 100;
            const int redLedChargeTime         = wait * 8;
            const int redLedDischargeTime      = wait * 46;
            const int blueLedChargeTime        = wait * 12; // 8
            const int blueLedDischargeTime     = wait * 60; // 42
            const int capacitorPreChargingTime = wait * 24;

            ConsoleEx.WriteLine(1, 7, string.Format("Pre charging capacitors for {0} ms-seconds ", capacitorPreChargingTime), ConsoleColor.Yellow);
            nusbio[regLedGpio].High();
            nusbio[blueLedGpio].High();
            Thread.Sleep(capacitorPreChargingTime);
            ConsoleEx.WriteLine(1, 7, "".PadRight(64), ConsoleColor.Cyan);

            var redLedTimeout  = new MadeInTheUSB.TimeOut(redLedChargeTime);
            var blueLedTimeout = new MadeInTheUSB.TimeOut(blueLedDischargeTime);

            // Turn blue LED off, red led stay on
            nusbio[blueLedGpio].DigitalWrite(PinState.Low);

            while (true)
            {
                if (blueLedTimeout.IsTimeOut())
                {
                    if (blueLedTimeout.Duration == blueLedChargeTime)
                    {
                        ConsoleEx.WriteLine(1, 7, "Blue Off".PadRight(64), ConsoleColor.Cyan);
                        nusbio[blueLedGpio].Low();
                        blueLedTimeout = new TimeOut(blueLedDischargeTime);
                    }
                    else
                    {
                        ConsoleEx.WriteLine(1, 7, "Blue On ".PadRight(64), ConsoleColor.Cyan);
                        nusbio[blueLedGpio].High();
                        blueLedTimeout = new TimeOut(blueLedChargeTime);
                    }
                }
                if (redLedTimeout.IsTimeOut())
                {
                    if (redLedTimeout.Duration == redLedChargeTime)
                    {
                        ConsoleEx.WriteLine(1, 8, "Red  Off".PadRight(64), ConsoleColor.Cyan);
                        nusbio[regLedGpio].Low();
                        redLedTimeout = new TimeOut(redLedDischargeTime);
                    }
                    else
                    {
                        ConsoleEx.WriteLine(1, 8, "Red  On ".PadRight(64), ConsoleColor.Cyan);
                        nusbio[regLedGpio].High();
                        redLedTimeout = new TimeOut(redLedChargeTime);
                    }
                }
                if (Console.KeyAvailable)
                {
                    if (Console.ReadKey().Key == ConsoleKey.Q)
                    {
                        break;
                    }
                }
                Thread.Sleep(wait);
            }
            nusbio[regLedGpio].DigitalWrite(PinState.Low);
            nusbio[blueLedGpio].DigitalWrite(PinState.Low);
        }