change.ino 883 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // This example toggles the debug LED (pin 13) on or off
  2. // when a button on pin 2 is pressed.
  3. // Include the Bounce2 library found here :
  4. // https://github.com/thomasfredericks/Bounce2
  5. #include <Bounce2.h>
  6. #define BUTTON_PIN 2
  7. #define LED_PIN 13
  8. int ledState = LOW;
  9. Bounce debouncer = Bounce(); // Instantiate a Bounce object
  10. void setup() {
  11. debouncer.attach(BUTTON_PIN,INPUT_PULLUP); // Attach the debouncer to a pin with INPUT_PULLUP mode
  12. debouncer.interval(25); // Use a debounce interval of 25 milliseconds
  13. pinMode(LED_PIN,OUTPUT); // Setup the LED
  14. digitalWrite(LED_PIN,ledState);
  15. }
  16. void loop() {
  17. debouncer.update(); // Update the Bounce instance
  18. if ( debouncer.fell() ) { // Call code if button transitions from HIGH to LOW
  19. ledState = !ledState; // Toggle LED state
  20. digitalWrite(LED_PIN,ledState); // Apply new LED state
  21. }
  22. }