Can't seem to control the LED on pin 3, using any of the four button switches. Only using 4 out of the 10 LED pins at the moment. Any ideas to why pin 3 is not responding would be greatly appreciated. The other LEDs and switches work.
// constants won't change. They're used here to
// set pin numbers:
const int ledPin[] = {3,4,5,6,7,8,9,10,11,12}; // the number of the LED pin
const int buttonPin[] = {14,15,16,13}; // pin A0,A1,A2,13
// Variables will change:
int ledState[] = {HIGH,HIGH,HIGH,HIGH}; // the current state of the output pin
int buttonState; // the current reading from the input pin
int lastButtonState[] = {LOW,LOW,LOW,LOW}; // the previous reading from the input pin
int c = 0;
int reading[]={0,1,2,3};
int state[] = {LOW,LOW,LOW,LOW};
int previous[] = {HIGH,HIGH,HIGH,HIGH};
// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
void setup() {
for(int x=0; x<4;x++){
pinMode(buttonPin[x], INPUT);
}
for(int i=0; i<4;i++){
pinMode(ledPin[i], OUTPUT);
}
}
void loop() {
// read the state of the switch into a local variable:
if(c > 4){
c = 0;
}
reading[c] = digitalRead(buttonPin[c]);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading[c] != lastButtonState[c]) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (reading[c] != buttonState) {
buttonState = reading[c];
// only toggle the LED if the new button state is HIGH
if (buttonState == HIGH) {
ledState[c] = !ledState[c];
}
}
}
// set the LED:
digitalWrite(ledPin[c], ledState[c]);
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
lastButtonState[c] = reading[c];
c++;
}