public void Run(IBackgroundTaskInstance taskInstance) { // Connect the Gas Sensor MQ2 to analog port 0 IGasSensorMQ2 sensor = DeviceFactory.Build.GasSensorMQ2(Pin.AnalogPin0); // Loop endlessly while (true) { try { // Check the value of the button, turn it into a string. string sensorvalue = sensor.SensorValue().ToString(); System.Diagnostics.Debug.WriteLine("Gas Sensor value is " + sensorvalue); } 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; }