PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

49 lines
884B

  1. // Detect the falling edge
  2. // Include the Bounce2 library found here :
  3. // https://github.com/thomasfredericks/Bounce-Arduino-Wiring
  4. #include <Bounce2.h>
  5. #define BUTTON_PIN 2
  6. #define LED_PIN 13
  7. int ledState = LOW;
  8. // Instantiate a Bounce object :
  9. Bounce debouncer = Bounce();
  10. void setup() {
  11. // Setup the button with an internal pull-up :
  12. pinMode(BUTTON_PIN,INPUT_PULLUP);
  13. // After setting up the button, setup the Bounce instance :
  14. debouncer.attach(BUTTON_PIN);
  15. debouncer.interval(500);
  16. // Setup the LED :
  17. pinMode(LED_PIN,OUTPUT);
  18. digitalWrite(LED_PIN,ledState);
  19. }
  20. void loop() {
  21. // Update the Bounce instance :
  22. debouncer.update();
  23. // Call code if Bounce fell (transition from HIGH to LOW) :
  24. if ( debouncer.fell() ) {
  25. // Toggle LED state :
  26. ledState = !ledState;
  27. digitalWrite(LED_PIN,ledState);
  28. }
  29. }