bool state = 0;
int buttonstate = 0;
int laststate = 0;
unsigned long lastdebounce = 0;
unsigned long debounceDelay = 50;
int counter = 0;
void setup() {
Serial.begin(9600);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
for (int i = 4; i <= 6; i++) {
pinMode(i, OUTPUT);
}
}
void loop() {
int reading = digitalRead(2);
if (reading != laststate) {
lastdebounce = millis();
}
if ((millis() - lastdebounce) > debounceDelay) {
if (reading != buttonstate) {
buttonstate = reading;
}
if (buttonstate == HIGH) {
counter++;
}
Serial.println(counter);
}
// switch (state) {
// case 0:
// digitalWrite(4, 1);
// state = 1;
// break;
// case 1:
// digitalWrite(5, 1);
// state = 2;
// break;
// case 2:
// digitalWrite(6, 1);
// state = 0;
// break;
// default:
// for (int i = 4; i <= 6; i++) {
// digitalWrite(i, 0);
// }
// break;
// }
laststate = reading;
}