#define BUTTON_PIN 3
#define BUTTON_RESET_PIN 2
#define LED_PIN 13
static byte pressCount = 0;
void setup() {
Serial.begin(9600);
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(BUTTON_RESET_PIN, INPUT_PULLUP);
pinMode(LED_PIN, OUTPUT);
attachInterrupt(digitalPinToInterrupt(BUTTON_RESET_PIN), reset, FALLING);
}
void loop() {
countButtonAndBlink();
}
void countButtonAndBlink()
{
static bool lastState = HIGH;
int currentState = digitalRead(BUTTON_PIN);
delay(12);
if(currentState == LOW & lastState == HIGH){
pressCount++;
blink(pressCount);
Serial.println(pressCount);
}
lastState = currentState;
}
void blink(int amount)
{
for (int i=0; i<amount; i++)
{
digitalWrite(LED_PIN, HIGH);
delay(250);
digitalWrite(LED_PIN,LOW);
delay(250);
}
}
void reset()
{
pressCount=0;
}