public void InitGpio() { var gpio = GpioController.GetDefault(); // Show an error if there is no GPIO controller if (gpio == null) { PushButtonpin = null; Ledpin = null; return; } Ledpin = gpio.OpenPin(led); PushButtonpin = gpio.OpenPin(pushButton); Ledpin.Write(GpioPinValue.High); Ledpin.SetDriveMode(GpioPinDriveMode.Output); Ledpin.Write(GpioPinValue.High); //if (PushButtonpin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp)) // PushButtonpin.SetDriveMode(GpioPinDriveMode.InputPullUp); //else PushButtonpin.SetDriveMode(GpioPinDriveMode.Input); //PushButtonpin.DebounceTimeout = TimeSpan.FromMilliseconds(50); //PushButtonpin.ValueChanged += buttonPin_ValueChanged; }
private async void Timer_Tick(object sender, object e) { if (!isCapturing) { if (PushButtonpin != null) { var val = PushButtonpin.Read(); if (i > 20 && val == GpioPinValue.Low && oldvalue == GpioPinValue.High) { isCapturing = true; await CapturePhoto(); } if (val == GpioPinValue.High && oldvalue == GpioPinValue.High) { i++; } else { i = 0; } oldvalue = val; } } }