Hi!
I am new here and with Arduino, and I cant figure out how to make the following code to work.
I have 8 leds and 8 button, but the button work if I use only 2 of them not all 8. Sorry for my english!
If someone here would like to help me I really apreciate.
Thank you!
// function reads the push button switch states, debounces and latches the LED states
// toggles the LED states on each push - release cycle
void ButtonDebounce(void)
{
static byte buttonState[8] = {LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW}; // the current reading from the input pin
static byte lastButtonState[8] = {LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW}; // the previous reading from the input pin
// 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.
static long lastDebounceTime[8] = {0}; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
byte reading[8];
reading[0] = digitalRead(41);
reading[1] = digitalRead(42);
reading[2] = digitalRead(43);
reading[3] = digitalRead(44);
reading[4] = digitalRead(45);
reading[5] = digitalRead(46);
reading[6] = digitalRead(47);
reading[7] = digitalRead(48);
for (int i = 0; i < 8; i++) {
if (reading != lastButtonState*) {*
* // 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 != buttonState*) {*
buttonState = reading*;*
* // only toggle the LED if the new button state is HIGH*
_ if (buttonState == HIGH) {
LED_state = !LED_state*;*
* }
}
}
} // end for() loop*_