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 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 Button to digital port 2 IButtonSensor button = DeviceFactory.Build.ButtonSensor(Pin.DigitalPin2); // Loop endlessly while (true) { try { // Check the value of the button. string buttonon = button.CurrentState.ToString(); // bool buttonison = buttonon.Equals("On", StringComparison.OrdinalIgnoreCase); System.Diagnostics.Debug.WriteLine("Button is " + buttonon); } 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; }
public MainPage() { this.InitializeComponent(); // initialise database try { db = new MySqlConnection("server=us-cdbr-azure-central-a.cloudapp.net;uid=b0a941f833069a;pwd=41561c96;database=as_eb778c54b5aa1fa;SslMode=None;charset=utf8;"); db.Open(); } catch (Exception e) { Debug.WriteLine("Failed to connect to db : " + e.Message); } // colors Blue = new SolidColorBrush(Colors.Blue); Green = new SolidColorBrush(Colors.Green); Red = new SolidColorBrush(Colors.Red); Gray = new SolidColorBrush(Colors.Gray); // initialise hardware _deviceFactory = DeviceFactory.Build; Display = _deviceFactory.RgbLcdDisplay(); Button = _deviceFactory.ButtonSensor(Pin.DigitalPin8); BlueLed = _deviceFactory.Led(Pin.DigitalPin2); GreenLed = _deviceFactory.Led(Pin.DigitalPin3); RedLed = _deviceFactory.Led(Pin.DigitalPin4); LightSensor = _deviceFactory.LightSensor(Pin.AnalogPin2); // line info CurrentWeight = LightSensor.SensorValue(); CurrentLine = 2; dbSet(CurrentLine); // update UI WeightText.Text = CurrentWeight.ToString(); // LED tests DispatcherTimer time = new DispatcherTimer(); time.Interval = TimeSpan.FromMilliseconds(5); time.Tick += tick; time.Start(); // light sensor to simulate weight DispatcherTimer weightUpdater = new DispatcherTimer(); weightUpdater.Interval = TimeSpan.FromSeconds(30); weightUpdater.Tick += updateWeight; weightUpdater.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 void Run(IBackgroundTaskInstance taskInstance) { deferral = taskInstance.GetDeferral(); buzzer = DeviceFactory.Build.Buzzer(Pin.DigitalPin2); button = DeviceFactory.Build.ButtonSensor(Pin.DigitalPin4); blueLed = DeviceFactory.Build.Led(Pin.DigitalPin5); redLed = DeviceFactory.Build.Led(Pin.DigitalPin6); lightSensor = DeviceFactory.Build.LightSensor(Pin.AnalogPin2); display = DeviceFactory.Build.RgbLcdDisplay(); buttonState = SensorStatus.Off; try { display.SetBacklightRgb(255, 0, 0); display.SetText("Hey Web Summit"); } catch (Exception ex) { System.Diagnostics.Debug.Write("Something happened: " + ex.ToString()); throw; } timer = ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick, TimeSpan.FromMilliseconds(200)); }
//------------------------------------------------------------------------------------------------------------------------ #endregion #region Constructor //------------------------------------------------------------------------------------------------------------------------ public ButtonWatcher(GrovePi.Pin pin) { buttonSensor = DeviceFactory.Build.ButtonSensor(pin); }
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 // // Build Sensors IButtonSensor Button = DeviceFactory.Build.ButtonSensor(Pin.DigitalPin6); ILed Red = DeviceFactory.Build.Led(Pin.DigitalPin2); ILed Blue = DeviceFactory.Build.Led(Pin.DigitalPin3); ILed Green = DeviceFactory.Build.Led(Pin.DigitalPin4); IRotaryAngleSensor Potentiometer = DeviceFactory.Build.RotaryAngleSensor(Pin.AnalogPin0); // Set initial values int State = 0; double Speed = 100; while (true) { Speed = Potentiometer.SensorValue(); // Speed can be adjusted between 0-1023 // Adjust values for a range between 100-1000 if (Speed < 100) { Speed = 100; } if (Speed > 1000) { Speed = 1000; } //Get button state string buttonon = Button.CurrentState.ToString(); bool buttonison = buttonon.Equals("On", StringComparison.OrdinalIgnoreCase); if (buttonison) { // Turn off all Leds and then turn on current Led Red.AnalogWrite(Convert.ToByte(0)); Green.AnalogWrite(Convert.ToByte(0)); Blue.AnalogWrite(Convert.ToByte(0)); switch (State) { case 0: Red.AnalogWrite(Convert.ToByte(255)); break; case 1: Blue.AnalogWrite(Convert.ToByte(255)); break; case 2: Green.AnalogWrite(Convert.ToByte(255)); break; } // If State is above 2 reset loop else add 1 if (State == 2) { State = 0; } else { State++; } } // Delay the task according to the Potentiometer value Task.Delay((int)Speed).Wait(); } }
public ButtonController(IButtonSensor buttonSensor) { this.buttonSensor = buttonSensor; }