Example #1
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            // Connect the Sound Sensor to digital port 5
            IPIRMotionSensor pirMotion = DeviceFactory.Build.PIRMotionSensor(Pin.DigitalPin5);

            // Loop endlessly
            while (true)
            {
                try
                {
                    // Check people motion
                    if (pirMotion.IsPeopleDetected())
                    {
                        System.Diagnostics.Debug.WriteLine("Have people motion");
                    }
                    Task.Delay(1000).Wait();
                }
                catch (Exception ex)
                {
                    // NOTE: There are frequent exceptions of the following:
                    // WinRT information: Unexpected number of bytes was transferred. Expected: '. Actual: '.
                    // This appears to be caused by the rapid frequency of writes to the GPIO
                    // These are being swallowed here/

                    // If you want to see the exceptions uncomment the following:
                    // System.Diagnostics.Debug.WriteLine(ex.ToString());
                }
            }
        }
 public SensorController()
 {
     temphumiSensor = DeviceFactory.Build.DHTTemperatureAndHumiditySensor(Pin.DigitalPin2, DHTModel.Dht11);
     pirMotion      = DeviceFactory.Build.PIRMotionSensor(Pin.DigitalPin3);
     button         = DeviceFactory.Build.ButtonSensor(Pin.DigitalPin4);
     relay          = DeviceFactory.Build.Relay(Pin.DigitalPin5);
     soundSensor    = DeviceFactory.Build.SoundSensor(Pin.AnalogPin0);
     lightSensor    = DeviceFactory.Build.LightSensor(Pin.AnalogPin1);
     gasSensor      = DeviceFactory.Build.GasSensorMQ2(Pin.AnalogPin2);
     display        = DeviceFactory.Build.OLEDDisplay128X64();
     motor          = DeviceFactory.Build.MiniMotorDriver();
     lockState      = false;
 }