ksj
Well-Known Member
C-like:
// Include the Bounce2 library found here :
// https://github.com/thomasfredericks/Bounce2
#include <Bounce2.h>
#define BUTTON_PIN_1 2
#define BUTTON_PIN_2 7
#define LED_PIN 3
#define LED_PIN1 4
int ledState = LOW; Bounce debouncer1 = Bounce(); Bounce debouncer2 = Bounce();
void setup() {
pinMode(BUTTON_PIN_1,INPUT_PULLUP); debouncer1.attach(BUTTON_PIN_1); debouncer1.interval(5);
pinMode(BUTTON_PIN_2,INPUT_PULLUP); debouncer2.attach(BUTTON_PIN_2); debouncer2.interval(25);
pinMode(LED_PIN,OUTPUT); pinMode(LED_PIN1,OUTPUT); digitalWrite(LED_PIN1,ledState);
}
void loop() {
debouncer1.update(); debouncer2.update(); int value1 = debouncer1.read(); int value2 = debouncer2.read();
if ( value1 == LOW ) { for (int i = 255; i >= 0; i--) { analogWrite(LED_PIN, i); } } else { digitalWrite(LED_PIN, LOW ); }
if ( debouncer2.fell() ) { ledState = !ledState; digitalWrite(LED_PIN1,ledState); }
}