const int switch0 = 8;
const int switch1 = 9;
// const int switch2 = 3;
void loop()
{
pinMode(switch0, INPUT_PULLUP);
pinMode(switch1, INPUT_PULLUP);
// pinMode(switch2, INPUT_PULLUP);
if (debounce(switch0) == HIGH) { // Doe dan iets!
}
if (debounce(switch1) == HIGH) { // Doe dan iets!
}
if (debounce(switch2) == HIGH) { // Doe dan iets!
}
}
boolean debounce(int pin)
{
boolean state;
boolean previousState;
previousState = digitalRead(pin);
for (int counter = 0; counter < 10; counter++)
{
delay(1); //wait 1 millisecond
state = digitalRead(pin); //read the pin
if (state != previousState)
{
counter = 0; //reset the counter
previousState = state;
}
}
return state;
}