1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #include <Bounce2.h>
- #define LED_PIN 13
- #define NUM_BUTTONS 8
- const uint8_t BUTTON_PINS[NUM_BUTTONS] = {2, 3, 4, 5, 6, 7, 8, 9};
- int ledState = LOW;
- Bounce * buttons = new Bounce[NUM_BUTTONS];
- void setup() {
- for (int i = 0; i < NUM_BUTTONS; i++) {
- buttons[i].attach( BUTTON_PINS[i] , INPUT_PULLUP );
- buttons[i].interval(25);
- }
-
- pinMode(LED_PIN, OUTPUT);
- digitalWrite(LED_PIN, ledState);
- }
- void loop() {
- bool needToToggleLed = false;
- for (int i = 0; i < NUM_BUTTONS; i++) {
-
- buttons[i].update();
-
- if ( buttons[i].fell() ) {
- needToToggleLed = true;
- }
- }
-
- if ( needToToggleLed ) {
-
- ledState = !ledState;
- digitalWrite(LED_PIN, ledState);
- }
- }
|