int buttonPins[] = {2,3,4,5}; // declare the button input pins
unsigned long debounceTimers[] = {0,0,0,0}; // Declare an array to hold the debounce timers
int debounceDelay = 200; // Set the debounce delay to 200 ms
void setup() {
Serial.begin(9600);// initialise serial communications:
//Set the button pins as inputs
pinMode(buttonPins[0],INPUT_PULLUP);
pinMode(buttonPins[1],INPUT_PULLUP);
pinMode(buttonPins[2],INPUT_PULLUP);
pinMode(buttonPins[3],INPUT_PULLUP);
Serial.println("Setup Complete");
}
void loop() {
for (int i = 0; i <= 3; i++) {
if ((millis()- (debounceTimers[i])) > debounceDelay) { //Check if the debounce delay has expired for this input
if (digitalRead(buttonPins[i])==LOW){
Serial.write(i);
Serial.println(i);
debounceTimers[i]=millis();
}
else{} //if the input does not read LOW, do nothing
}else{} //If the debounce timer has not expired, do nothing
}
}