int test1 = 0;
boolean blocklast = false;
unsigned long MB[6] = {34, 39, 35, 0, 5, 6};
unsigned long MyPreviousMillis[6], tempstate[6], lastAtm, tm;
unsigned long laststate[6] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH};
void setup() {
// put your setup code here, to run once:
for (int MyButton = 0; MyButton <= 1; MyButton++)
pinMode(MB[MyButton], INPUT);
Serial.begin(115200);
}
void loop() {
tm = millis();
if ((tm - lastAtm) >= 100UL ) //Abtastrate //Entprellung
{
lastAtm = tm; //Letzte abtastung setzen
if ((!tempstate[0] && !laststate[0] && !tempstate[1] && !laststate[1]))
{
test1 = 0;
laststate[0] = HIGH;
laststate[1] = HIGH;
tempstate[0] = HIGH;
tempstate[1] = HIGH;
} else
for (int MyButton = 0; MyButton <= 1; MyButton++) { //Buttons durchgehen
tempstate[MyButton] = digitalRead(MB[MyButton]); //Button einlesen
if ( tempstate[MyButton] == LOW) { //Gedrückt?
if (!laststate[MyButton]) { //War der Button vorher schon gedrückt?
if ( tm - MyPreviousMillis[MyButton] >= 200) {//wiederholzeit bei gedrückt
MyPreviousMillis[MyButton] = tm;
blocklast = true; //Blockiere beim loslassen einen weiteren Auslöser
if (MyButton == 0)Serial.println(--test1); else if (MyButton == 1)Serial.println(++test1); //Mache hier was für den jeweiligen Button, bestenfalls switch-case
}
} //Ende:War der Button vorher schon gedrückt?
laststate[MyButton] = tempstate[MyButton];
} else {
if (laststate[MyButton] == LOW) { //War der Button vorher gedrückt?
if (MyButton == 0 && !blocklast)Serial.println(--test1);
if (MyButton == 1 && !blocklast)Serial.println(++test1);
blocklast = false;
laststate[MyButton] = HIGH;
}
}
}
}
}
Comments