private static void DetectButtonLed(GpioDriver driver) { using (var controller = new GpioController(driver)) { GpioPin button = controller.OpenPin(s_buttonPinNumber, PinMode.Input); if (button.IsModeSupported(PinMode.InputPullDown)) { button.Mode = PinMode.InputPullDown; } GpioPin led = controller.OpenPin(s_ledPinNumber, PinMode.Output); button.DebounceTimeout = TimeSpan.FromSeconds(1); button.NotifyEvents = PinEvent.SyncFallingEdge; button.ValueChanged += OnPinValueChanged2; button.EnableRaisingEvents = true; Stopwatch watch = Stopwatch.StartNew(); while (watch.Elapsed.TotalSeconds < 15) { Thread.Sleep(TimeSpan.FromSeconds(1)); } } }
private static void ButtonWait(GpioDriver driver) { using (var controller = new GpioController(driver)) { GpioPin button = controller.OpenPin(s_buttonPinNumber, PinMode.Input); if (button.IsModeSupported(PinMode.InputPullDown)) { button.Mode = PinMode.InputPullDown; } button.DebounceTimeout = TimeSpan.FromSeconds(1); button.NotifyEvents = PinEvent.SyncRisingEdge; Stopwatch watch = Stopwatch.StartNew(); while (watch.Elapsed.TotalSeconds < 15) { bool eventDetected = button.WaitForEvent(TimeSpan.FromSeconds(1)); if (eventDetected) { Console.WriteLine("Button pressed!"); } } } }
private static void DetectButton(GpioDriver driver) { using (var controller = new GpioController(driver)) { GpioPin button = controller.OpenPin(s_buttonPinNumber, PinMode.Input); if (button.IsModeSupported(PinMode.InputPullDown)) { button.Mode = PinMode.InputPullDown; } button.DebounceTimeout = TimeSpan.FromMilliseconds(100); button.NotifyEvents = PinEvent.SyncFallingRisingEdge; button.ValueChanged += OnPinValueChanged1; button.EnableRaisingEvents = true; Stopwatch watch = Stopwatch.StartNew(); while (watch.Elapsed.TotalSeconds < 15) { Thread.Sleep(1 * 100); if (s_buttonPressed) { Console.WriteLine($"Button press!"); } } } }