I am trying to wrap my head around some code i have found. But this is a little beyond me. I need a code that has multible buttons and leds. each button has an led associated to it. Press button #1, led #1 lights up and stays lit till you hit another button. when hit the other another button, that buttons associated led lights up and stay lit till.......
i have been looking at this code, but i think its more of an on/off type, but close.
// One Button On/Off Toggle
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// Variables will change:
int ledState = LOW; // the current state of the output pin
int buttonState = LOW; // the current reading from the input pin
int lastButtonState = HIGH; // the previous reading from the input pin
int reading;
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
lastButtonState = reading;
}
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (buttonState != lastButtonState) {
buttonState = lastButtonState;
if (buttonState == HIGH) {
ledState = !ledState;
digitalWrite(ledPin, ledState);
}
}
}
}
At the end of this project, i should hope to have 6 buttons and 6 leds. I have already did the wiring schem. Just looking for a little(most likely alot) help on this on. Thank you