public void Run(IBackgroundTaskInstance taskInstance) { // Connect the Ultrasonic Sensor to digital port 4 IUltrasonicRangerSensor sensor = DeviceFactory.Build.UltraSonicSensor(Pin.DigitalPin4); // Loop endlessly while (true) { Task.Delay(100).Wait(); //Delay 0.1 second try { // Check the value of the Ultrasonic Sensor string sensorvalue = sensor.MeasureInCentimeters().ToString(); System.Diagnostics.Debug.WriteLine("Ultrasonic reads " + 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()); } } }
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(); }
private async void MainPage_Loaded(object sender, RoutedEventArgs e) { sendingPhoto = false; panicLed = DeviceFactory.Build.Led(Pin.DigitalPin2); infoLed = DeviceFactory.Build.Led(Pin.DigitalPin4); ranger = DeviceFactory.Build.UltraSonicSensor(Pin.DigitalPin3); screen = DeviceFactory.Build.RgbLcdDisplay(); screen.SetText("setting up..."); screen.SetBacklightRgb(0, 0, 200); // init mode -> Both Led's are on panicLed.ChangeState(SensorStatus.On); infoLed.ChangeState(SensorStatus.On); // init camera camera = new UsbCamera(); var initWorked = await camera.InitializeAsync(); // Something went wrong if (!initWorked || ranger.MeasureInCentimeters() == -1) { infoLed.ChangeState(SensorStatus.Off); screen.SetText("Camera or Sensor not connected!"); screen.SetBacklightRgb(200, 0, 0); blink(panicLed); return; } // init photobackend Microsoft.WindowsAzure.Storage.Auth.StorageCredentials credentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(accountName, accountKey); //credentials.UpdateSASToken("?sv=2015-04-05&ss=b&srt=sco&sp=rwlac&se=2016-11-20T04:05:54Z&st=2016-11-12T20:05:54Z&spr=https,http&sig=B0zDabRXoO7LfWy5iACsn0sHOnWzvmmrDv8fAqITPgI%3D"); CloudStorageAccount acc = new CloudStorageAccount(credentials, true); CloudBlobClient client = acc.CreateCloudBlobClient(); container = client.GetContainerReference("picture-storage"); previewElement.Source = camera.MediaCaptureInstance; await camera.StartCameraPreview(); // init finished - turn off panic Led infoLed.ChangeState(SensorStatus.Off); panicLed.ChangeState(SensorStatus.Off); screen.SetText(""); screen.SetBacklightRgb(0, 0, 0); DispatcherTimer mainThread = new DispatcherTimer(); mainThread.Interval = TimeSpan.FromSeconds(0.5); mainThread.Tick += run; mainThread.Start(); }
public Pi() { var builder = DeviceFactory.Build; _display = builder.RgbLcdDisplay(); _light = builder.LightSensor(Pin.AnalogPin0); _led = builder.Led(Pin.DigitalPin7); //_temp = builder.TemperatureAndHumiditySensor(Pin.AnalogPin1, TemperatureAndHumiditySensorModel.DHT11); _ultrasonicRanger = builder.UltraSonicSensor(Pin.DigitalPin3); _button = builder.ButtonSensor(Pin.DigitalPin2); //_buzzer = builder.Buzzer(Pin.DigitalPin3); }
public MainPage() { InitializeComponent(); _goPiGo = DeviceFactory.Build.BuildGoPiGo(); _goPiGo.MotorController().EnableServo(); _devices = DeviceFactory.Build.BuildUltraSonicSensor(Pin.Trigger); System.Diagnostics.Debug.WriteLine("Start Listener"); ServerSocketConnection.StartListener(); ServerSocketConnection.NewMessageReady += SendCommand; Loaded += MainPage_Loaded; }
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); } } }
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(); }