static void Main(string[] args) { // Set debounce delay to 5ms int debounceDelay = 50000; int pin = 7; Console.WriteLine($"Let's blink an on-board LED!"); using GpioController controller = new GpioController(PinNumberingScheme.Board, new OrangePi4Driver()); using BoardLed led = new BoardLed("status_led"); controller.OpenPin(pin, PinMode.InputPullUp); led.Trigger = "none"; Console.WriteLine($"GPIO pin enabled for use: {pin}."); Console.WriteLine("Press any key to exit."); while (!Console.KeyAvailable) { if (Debounce()) { // Button is pressed led.Brightness = 1; } else { // Button is unpressed led.Brightness = 0; } } bool Debounce() { long debounceTick = DateTime.Now.Ticks; PinValue buttonState = controller.Read(pin); do { PinValue currentState = controller.Read(pin); if (currentState != buttonState) { debounceTick = DateTime.Now.Ticks; buttonState = currentState; } }while (DateTime.Now.Ticks - debounceTick < debounceDelay); if (buttonState == PinValue.Low) { return(true); } else { return(false); } } }
/// <summary> /// Entry point for example program /// </summary> /// <param name="args">Command line arguments</param> public static void Main(string[] args) { // Open the green led on Raspberry Pi. using BoardLed led = new BoardLed("led0"); string defaultTrigger = led.Trigger; // LED can be controlled only if the trigger is set to none. led.Trigger = "none"; // Do your job. for (int i = 0; i < 10; i++) { // Because the Raspberry Pi LED does not support dimming, brightness values greater than 0 can turn the LED on. led.Brightness = 1; Thread.Sleep(500); led.Brightness = 0; Thread.Sleep(500); } // Give the control of led to the kernel. led.Trigger = defaultTrigger; }