예제 #1
0
파일: Program.cs 프로젝트: JohnXi001/iot-1
        public static void Main(string[] args)
        {
            // get the GPIO controller
            GpioController ledController = new GpioController(PinNumberingScheme.Logical);

            // open PIN 27 for led
            ledController.OpenPin(ledPin, PinMode.Output);

            // initialize PIR sensor
            using (Iot.Device.Hcsr501.Hcsr501 sensor =
                       new Iot.Device.Hcsr501.Hcsr501(hcsr501Pin, PinNumberingScheme.Logical))
            {
                // loop
                while (true)
                {
                    // adjusting the detection distance and time by rotating the potentiometer on the sensor
                    if (sensor.IsMotionDetected == true)
                    {
                        // turn the led on when the sensor detected infrared heat
                        ledController.Write(ledPin, PinValue.High);
                        Console.WriteLine("Detected! Turn the LED on.");
                    }
                    else
                    {
                        // turn the led off when the sensor undetected infrared heat
                        ledController.Write(ledPin, PinValue.Low);
                        Console.WriteLine("Undetected! Turn the LED off.");
                    }

                    // wait for a second
                    Thread.Sleep(1000);
                }
            }
        }
예제 #2
0
        public static void Main(string[] args)
        {
            GpioController ledController = new GpioController();

            ledController.OpenPin(LedPin, PinMode.Output);

            using (Iot.Device.Hcsr501.Hcsr501 sensor =
                       new Iot.Device.Hcsr501.Hcsr501(Hcsr501Pin))
            {
                while (true)
                {
                    // adjusting the detection distance and time by rotating the potentiometer on the sensor
                    if (sensor.IsMotionDetected)
                    {
                        // turn the led on when the sensor detected infrared heat
                        ledController.Write(LedPin, PinValue.High);
                        Console.WriteLine("Detected! Turn the LED on.");
                    }
                    else
                    {
                        // turn the led off when the sensor undetected infrared heat
                        ledController.Write(LedPin, PinValue.Low);
                        Console.WriteLine("Undetected! Turn the LED off.");
                    }

                    Thread.Sleep(1000);
                }
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            // get the GPIO controller
            GpioController ledController = new GpioController(PinNumberingScheme.Logical);

            // open PIN 27 for led
            ledController.OpenPin(ledPin, PinMode.Output);

            // initialize PIR sensor
            Iot.Device.Hcsr501.Hcsr501 sensor = new Iot.Device.Hcsr501.Hcsr501(hcsr501Pin, PinNumberingScheme.Logical);
            sensor.Initialize();

            // loop
            while (true)
            {
                if (sensor.Read() == true)
                {
                    // turn the led on when the sensor detected infrared heat
                    ledController.Write(ledPin, PinValue.High);
                    Console.WriteLine("Detected! Turn the LED on.");
                }
                else
                {
                    // turn the led off when the sensor undetected infrared heat
                    ledController.Write(ledPin, PinValue.Low);
                    Console.WriteLine("Undetected! Turn the LED off.");
                }

                // wait for a second
                Thread.Sleep(1000);
            }
        }