PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. }