#define BUTTON_PIN 3
#define BUTTON_RESET_PIN 2
#define LED_PIN 13
volatile bool ledState = false;
static bool buttonPressed = false;
static byte pressCount = 0;
void countButtonAndBlink()
{
bool currentState = digitalRead(BUTTON_PIN);
if (currentState==false)
{
delay(50);
buttonPressed=true;
}
if (buttonPressed)
{
buttonPressed = false;
pressCount++;
blink(pressCount);
Serial.println(pressCount);
}
}
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() //für aufg.2
{
pressCount=0;
buttonPressed=false;
delay(50);
Serial.println(pressCount);
}
void setup() {
Serial.begin(9600);
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(BUTTON_RESET_PIN, INPUT_PULLUP); //für 2
pinMode(LED_PIN, OUTPUT);
attachInterrupt(digitalPinToInterrupt(BUTTON_RESET_PIN), reset, CHANGE); //für 2
}
void loop() {
countButtonAndBlink();
}