Exemplo n.º 1
0
        public void Run()
        {
            Stopwatch sw = new Stopwatch();

            while (true)
            {
                sw.Restart();
                statusLED.TurnOn();
                Measure();
                if (measureInterval < INACTIVE_MEASURE_INTERVAL)
                {
                    Signal();
                }
                else
                {
                    distanceLED.TurnOff();
                }
                // Console.WriteLine("Measured distance: {0:000.000}m.", distance);
                if (sw.ElapsedMilliseconds < MIN_STATUS_BLINK_INTERVAL)
                {
                    Thread.Sleep(Math.Max(MIN_STATUS_BLINK_INTERVAL - (int)sw.ElapsedMilliseconds, 0));
                }
                statusLED.TurnOff();
                Thread.Sleep(Math.Max(measureInterval - (int)sw.ElapsedMilliseconds, 0));
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Launching GarageAssistant...");
            LED green = new LED(Pi.Gpio.GetGpioPinByBcmPinNumber(20));
            LED red   = new LED(Pi.Gpio.GetGpioPinByBcmPinNumber(21));
            UltrasoundSensor sensor = new UltrasoundSensor(
                Pi.Gpio.GetGpioPinByBcmPinNumber(2),
                Pi.Gpio.GetGpioPinByBcmPinNumber(3)
                );

            Console.CancelKeyPress += (sender, e) =>
            {
                Console.WriteLine("Terminating...");
                green.TurnOff();
                red.TurnOff();
            };

            Daemon daemon = new Daemon(
                statusLED: green,
                distanceLED: red,
                ultrasoundSensor: sensor
                );

            daemon.Run();
        }