private void OnLoaded(object sender, RoutedEventArgs routedEventArgs) { var controller = GpioController.GetDefault(); if (null != controller) { LedPin = controller.OpenPin(5); LedPin.SetDriveMode(GpioPinDriveMode.Output); LedPin.Write(GpioPinValue.Low); // set light to off at start up SoundPin = controller.OpenPin(6); SoundPin.SetDriveMode(GpioPinDriveMode.Input); SoundPin.ValueChanged += (pin, args) => { var pinValue = SoundPin.Read(); if (pinValue == GpioPinValue.Low) { Debug.WriteLine("Sound Detected!"); LedPin.Write(IsLightOn ? GpioPinValue.Low : GpioPinValue.High); IsLightOn = !IsLightOn; } }; } }
public async Task ReceiveCloudToDeviceMessageAsync() { CloudToDeviceLog = "Receiving events..."; Debug.WriteLine("\nReceiving cloud to device messages from service"); while (true) { Message receivedMessage = await DeviceClient.ReceiveAsync(); if (receivedMessage == null) { continue; } var msg = Encoding.ASCII.GetString(receivedMessage.GetBytes()); CloudToDeviceLog += "\nReceived message: " + msg; if (msg == "on") { LedPin.Write(GpioPinValue.Low); } if (msg == "off") { LedPin.Write(GpioPinValue.High); } await DeviceClient.CompleteAsync(receivedMessage); } }
public TreatDispenser(GpioController controller) { _ledPin = LedPin.Initialize(controller, 18, LedPinState.Off); _buttonPin = ButtonPin.Initialize(controller, 23, PinMode.InputPullDown); _buttonPin.OnButtonUp += async(s, e) => { await DispenseAsync().ConfigureAwait(false); }; }
public MainViewModel() { DeviceClient = DeviceClient.Create(IotHubUri, new DeviceAuthenticationWithRegistrySymmetricKey(DeviceId, DeviceKey)); GpioController = GpioController.GetDefault(); if (null != GpioController) { LedPin = GpioController.OpenPin(4); LedPin.SetDriveMode(GpioPinDriveMode.Output); } }
public MainPage() { this.InitializeComponent(); GpioController = GpioController.GetDefault(); BuzzPin = GpioController.OpenPin(5); BuzzPin.SetDriveMode(GpioPinDriveMode.Output); BuzzPin.Write(GpioPinValue.High); LedPin = GpioController.OpenPin(6); LedPin.SetDriveMode(GpioPinDriveMode.Output); LedPin.Write(GpioPinValue.High); }
private async Task MorseToBeep(string morse) { foreach (var c in morse) { switch (c) { case '.': BuzzPin.Write(GpioPinValue.Low); LedPin.Write(GpioPinValue.Low); await Task.Delay(100); BuzzPin.Write(GpioPinValue.High); LedPin.Write(GpioPinValue.High); break; case '-': BuzzPin.Write(GpioPinValue.Low); LedPin.Write(GpioPinValue.Low); await Task.Delay(300); BuzzPin.Write(GpioPinValue.High); LedPin.Write(GpioPinValue.High); break; case '/': BuzzPin.Write(GpioPinValue.High); LedPin.Write(GpioPinValue.High); await Task.Delay(200); break; default: break; } await Task.Delay(50); } }
public MainPage() { this.InitializeComponent(); GpioController = GpioController.GetDefault(); if (null != GpioController) { ReedPin = GpioController.OpenPin(5); ReedPin.SetDriveMode(GpioPinDriveMode.Input); ReedPin.ValueChanged += (sender, args) => { if (ReedPin.Read() == GpioPinValue.Low) { IsLightOn = !IsLightOn; LedPin.Write(IsLightOn ? GpioPinValue.Low : GpioPinValue.High); } }; LedPin = GpioController.OpenPin(6); LedPin.SetDriveMode(GpioPinDriveMode.Output); LedPin.Write(GpioPinValue.High); } }
public void TurnOff() { LedPin.Write(GpioPinValue.Low); IsOn = false; }
public void TurnOn() { LedPin.Write(GpioPinValue.High); IsOn = true; }
private void InitializeLed(GpioController controller) { LedPin = controller.OpenPin(LedPinNumber); LedPin.SetDriveMode(GpioPinDriveMode.Output); LedPin.Write(IsOn ? GpioPinValue.High : GpioPinValue.Low); }
private void SetLedState(LedPin eled, bool state) { Console.WriteLine("Setting led {0} {1}", eled, state); gpioPinsConnection[LedToPin.TryGetOrDefault(eled)] = state; }