public void Run(IBackgroundTaskInstance taskInstance) { // Get the deferral instance deferral = taskInstance.GetDeferral(); // Instantiate the sensors and actuators buzzer = DeviceFactory.Build.Buzzer(Pin.DigitalPin2); button = DeviceFactory.Build.ButtonSensor(Pin.DigitalPin4); blueLed = DeviceFactory.Build.Led(Pin.DigitalPin5); redLed = DeviceFactory.Build.Led(Pin.DigitalPin6); soundSensor = DeviceFactory.Build.SoundSensor(Pin.AnalogPin0); lightSensor = DeviceFactory.Build.LightSensor(Pin.AnalogPin2); display = DeviceFactory.Build.RgbLcdDisplay(); // The IO to the GrovePi sensors and actuators can generate a lot // of exceptions - wrap all GrovePi API calls in try/cath statements. try { // Set the RGB backlight to red and display a message display.SetBacklightRgb(255, 0, 0); display.SetText("The Thingy is getting started"); } catch (Exception ex) { // On Error, Resume Next :) } // Start a timer to check the sensors and activate the actuators five times per second timer = ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick, TimeSpan.FromMilliseconds(200)); }
public void Run(IBackgroundTaskInstance taskInstance) { // Connect the Sound Sensor to analog port 0 ISoundSensor sensor = DeviceFactory.Build.SoundSensor(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("Sound 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 void Run(IBackgroundTaskInstance taskInstance) { // // TODO: Insert code to perform background work // // If you start any asynchronous methods here, prevent the task // from closing prematurely by using BackgroundTaskDeferral as // described in http://aka.ms/backgroundtaskdeferral // _deferral = taskInstance.GetDeferral(); // set the security for fms, and hook into fms ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; fmserver = GetFMSInstance(); // get the sensors lightSensor = DeviceFactory.Build.LightSensor(Pin.AnalogPin0); soundSensor = DeviceFactory.Build.SoundSensor(Pin.AnalogPin2); leds = DeviceFactory.Build.BuildLedBar(Pin.DigitalPin8); leds.Initialize(GrovePi.Sensors.Orientation.GreenToRed); // start the timer ThreadPoolTimer timer = ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick, TimeSpan.FromSeconds(1)); }
private void InitGrovePi() { System.Diagnostics.Debug.WriteLine(DeviceFactory.Build.GrovePi().GetFirmwareVersion()); GroveRotary = DeviceFactory.Build.RotaryAngleSensor(Pin.AnalogPin0); GroveSound = DeviceFactory.Build.SoundSensor(Pin.AnalogPin1); GroveLight = DeviceFactory.Build.LightSensor(Pin.AnalogPin2); GroveRelay = DeviceFactory.Build.Relay(Pin.DigitalPin2); GroveTempHumi = DeviceFactory.Build.DHTTemperatureAndHumiditySensor(Pin.DigitalPin3, DHTModel.Dht11); GroveRanger = DeviceFactory.Build.UltraSonicSensor(Pin.DigitalPin4); GroveLedBar = DeviceFactory.Build.BuildLedBar(Pin.DigitalPin5); GroveBuzzer = DeviceFactory.Build.Buzzer(Pin.DigitalPin6); GroveButton = DeviceFactory.Build.ButtonSensor(Pin.DigitalPin7); GroveLCD = DeviceFactory.Build.RgbLcdDisplay(); GroveLedBar.Initialize(GrovePi.Sensors.Orientation.GreenToRed); GroveLCD.SetBacklightRgb(255, 50, 255); DeviceFactory.Build.GrovePi().PinMode(Pin.DigitalPin2, PinMode.Output); Delay.Milliseconds(10); DeviceFactory.Build.GrovePi().Flush(); DeviceFactory.Build.GrovePi().PinMode(Pin.DigitalPin6, PinMode.Output); Delay.Milliseconds(10); DeviceFactory.Build.GrovePi().Flush(); }
public MainPage() { this.InitializeComponent(); deviceClient = DeviceClient.Create(iotHubUri, new DeviceAuthenticationWithRegistrySymmetricKey("GrovePiSoundSensor", deviceKey), TransportType.Http1); soundsensor = DeviceFactory.Build.SoundSensor(Pin.AnalogPin0); lcd = DeviceFactory.Build.RgbLcdDisplay().SetText("Hello").SetBacklightRgb(0, 0, 255); timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromMilliseconds(5000); timer.Tick += Timer_Tick; timer.Start(); }
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; }
public MainViewModel() { WindowClosingCommand = new DelegateCommand(OnWindowClosing); Data = new SensorData(); Data.SensorName = SensorName; var factory = new ConnectionFactory() { HostName = HostName, UserName = UserName, Password = Password }; _busConnection = factory.CreateConnection(); _busChannel = _busConnection.CreateModel(); _busChannel.ExchangeDeclare(exchange: ExchangeName, type: "fanout"); _sensor = new SoundSensor(); _sensor.PeakAcquired += OnPeak; _sensor.Start(SamplingInterval); }
/// <summary> /// Main page constructor /// </summary> public MainPage() { this.InitializeComponent(); // Hard coding guid for sensors. Not an issue for this particular application which is meant for testing and demos List <ConnectTheDotsSensor> sensors = new List <ConnectTheDotsSensor> { new ConnectTheDotsSensor("2298a348-e2f9-4438-ab23-82a3930662ab", "Sound", "Amp"), }; ctdHelper = new ConnectTheDotsHelper(serviceBusNamespace: ConnectionStrings.ServicebusNamespaceDefault, eventHubName: ConnectionStrings.EventHubNameDefault, keyName: ConnectionStrings.KeyNameDefault, key: ConnectionStrings.KeyDefault, displayName: ConnectionStrings.DisplayNameDefault, organization: ConnectionStrings.OrganizationDefault, location: ConnectionStrings.LocationDefault, sensorList: sensors); soundsensor = DeviceFactory.Build.SoundSensor(Pin.AnalogPin0); lcd = DeviceFactory.Build.RgbLcdDisplay().SetText("Hello").SetBacklightRgb(0, 0, 255); timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromMilliseconds(5000); timer.Tick += Timer_Tick; timer.Start(); }
public void Run(IBackgroundTaskInstance taskInstance) { // LCD - This screen is I2C IRgbLcdDisplay LCD = DeviceFactory.Build.RgbLcdDisplay(); LCD.SetBacklightRgb(255, 255, 255); LCD.SetText("Hello world!"); // Not sure what colour this will show up in // LEDs ILed red = DeviceFactory.Build.Led(Pin.DigitalPin2); ILed blue = DeviceFactory.Build.Led(Pin.DigitalPin3); // Ultrasonic IUltrasonicRangerSensor Ultrasonic = DeviceFactory.Build.UltraSonicSensor(Pin.DigitalPin4); // Temperature and Humidity // TODO: Double check Sensor model number. Assumed DHT11 from the GrovePi+ Starter Kit IDHTTemperatureAndHumiditySensor tempHumidity = DeviceFactory.Build.DHTTemperatureAndHumiditySensor(Pin.DigitalPin5, DHTModel.Dht11); // Sound sensor ISoundSensor Sound = DeviceFactory.Build.SoundSensor(Pin.AnalogPin0); // LDR IRotaryAngleSensor LDR = DeviceFactory.Build.RotaryAngleSensor(Pin.AnalogPin1); while (true) { Task.Delay(100).Wait(); try { // Ultrasonic sensor int distance = Ultrasonic.MeasureInCentimeters(); Debug.WriteLine("Distance: " + distance.ToString()); // TODO - tune to distance of door //if(distance < 50) // LDR int lightLevel = LDR.SensorValue(); Debug.WriteLine("Light Level: " + lightLevel.ToString()); // LEDs red.ChangeState(SensorStatus.On); blue.ChangeState(SensorStatus.On); // Temperature Humidity tempHumidity.Measure(); double temp_degC = tempHumidity.TemperatureInCelsius; double humidity = tempHumidity.Humidity; Debug.WriteLine("Temperature: " + temp_degC + "\tHumidity: " + humidity); // Sound sensor int soundLevel = Sound.SensorValue(); Debug.WriteLine("Sound Level: " + soundLevel); // TODO: Send data to Azure } catch (Exception ex) { Debug.WriteLine(ex.Message); } } }