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;
            }
            
            var clockPin           = NusbioGpio.Gpio6; // White, Arduino A5
            var dataOutPin         = NusbioGpio.Gpio5; // Green, Arduino A4

            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");
                    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(MCP9808_TemperatureSensor.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 #2
0
        private static bool WaitForSensorsToBeReady(MCP9808_TemperatureSensor mcp9808_TemperatureSensor)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, GetAssemblyProduct(), ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            ConsoleEx.TitleBar(ConsoleEx.WindowHeight-2, Nusbio.GetAssemblyCopyright(), ConsoleColor.White, ConsoleColor.DarkBlue);
            ConsoleEx.WriteMenu(-1, 4, "Q)uit");

            while (true)
            {
                if (mcp9808_TemperatureSensor.Begin())
                    return true;
                else
                    ConsoleEx.Write(0, 2, string.Format("[{0}]MCP9808 I2C Temperature sensor not connected to Nusbio", DateTime.Now), ConsoleColor.Cyan);

                TimePeriod.Sleep(2*1000);
                if (Console.KeyAvailable)
                {
                    var k = Console.ReadKey(true).Key;
                    if (k == ConsoleKey.Q)
                        return false;
                }
            }
        }