#define LED_PIN 6
#define TASTER_PIN 5
void setup() {
pinMode (TASTER_PIN, INPUT_PULLUP);
pinMode (LED_PIN, OUTPUT);
Serial.begin(9600); // put your setup code here, to run once:
}
void loop() {
bool buttonState = digitalRead(TASTER_PIN);
static bool lastButtonState = 1;
static int counter = 0;
unsigned long currentTime = millis();
static unsigned long lastDebounce = 0;
const unsigned long debounceTime = 50;
if (buttonState != lastButtonState && (currentTime - lastDebounce >= debounceTime)) {
lastDebounce = currentTime ;
if (buttonState == LOW){
counter +=1 ;
Serial.println (counter);
blink(counter); // put your main code here, to run repeatedly:
}
}
lastButtonState = buttonState ;
}
void blink (int blinks) {
for (int b = 0; b < blinks; b++) {
digitalWrite(LED_PIN, HIGH);
delay (500);
digitalWrite(LED_PIN, LOW);
delay (500);
}
}