first commit
This commit is contained in:
commit
a5a0434432
1126 changed files with 439481 additions and 0 deletions
41
Software/CSharp/Samples/GasSensorMQ2/StartupTask.cs
Normal file
41
Software/CSharp/Samples/GasSensorMQ2/StartupTask.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
using Windows.ApplicationModel.Background;
|
||||
|
||||
// Add using statements to the GrovePi libraries
|
||||
using GrovePi;
|
||||
using GrovePi.Sensors;
|
||||
|
||||
namespace GasSensorMQ2
|
||||
{
|
||||
public sealed class StartupTask : IBackgroundTask
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue