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.

49 line
923B

  1. #include <Bounce.h>
  2. // As long as the button is held down, the LED will blink
  3. // Build the circuit indicated here: http://arduino.cc/en/Tutorial/Button
  4. #define BUTTON 2
  5. #define LED 13
  6. // A variable to store the current LED state
  7. int ledState = LOW;
  8. // Instantiate a Bounce object with a 5 millisecond debounce time
  9. Bounce bouncer = Bounce( BUTTON,5 );
  10. void setup() {
  11. pinMode(BUTTON,INPUT);
  12. pinMode(LED,OUTPUT);
  13. }
  14. void loop() {
  15. // Update and monitor a change of input
  16. if ( bouncer.update() ) {
  17. // Get the state of the button
  18. int value = bouncer.read();
  19. // Toggle the LED if the button is held
  20. if ( value == HIGH) {
  21. // Make the button retrigger in 500 milliseconds
  22. bouncer.rebounce(500);
  23. if ( ledState == LOW ) {
  24. ledState = HIGH;
  25. } else {
  26. ledState = LOW;
  27. }
  28. } else {
  29. ledState = LOW;
  30. }
  31. digitalWrite(LED, ledState );
  32. }
  33. }