#define TASTERPIN 8
#define LED_PIN 6
void setup() {
Serial.begin(9600);
pinMode(TASTERPIN, INPUT_PULLUP);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
bool tasterstatus = digitalRead(TASTERPIN);
static bool vorherigerTasterstatus = 1;
static int zaehlwert = 0;
static unsigned long letzteEntprellzeit = 0;
const unsigned long entprellIntervall = 50;
unsigned long aktuelleZeit = millis();
digitalWrite(LED_PIN, !tasterstatus);
if (tasterstatus != vorherigerTasterstatus && (aktuelleZeit - letzteEntprellzeit >= entprellIntervall)) {
letzteEntprellzeit = aktuelleZeit;
{
if (tasterstatus == LOW){
zaehlwert += 1;
Serial.println("Zählwert: "+ String(zaehlwert));
}
vorherigerTasterstatus = tasterstatus;
}
}
}