yea nothing has worked, i have tried many things such as
lastButtonState1 = buttonState1;
lastButtonState2 = buttonState2;
its just not saving my button press...
i want the led to stay on when i press the button, and turn off when i press the button again.
my overall goal is to figure out a way to take these two buttons and create a timer attached to the buttons to regulate my home lights.
so what i want is when i press the button once, it starts a timer and turns on the led, i want this for 2 buttons so that they are independent from each other.
however what i want is to learn how this works, how each button is working, but im jammed up i want this to stay in memory when i press the button but what its doing is as i press the button the led comes on, when i release the button it turns off, i want this to stay on untill i press the button again. my code is as fallows
const int buttonPin1 = 2; // the number of the pushbutton pin
const int buttonPin2 = 3; // the number of the pushbutton pin
const int ledPin1 = 12; // the number of the LED pin
const int ledPin2 = 13; // the number of the LED pin
// Variables will change:
int ledState1 = HIGH; // the current state of the output pin
int ledState2 = HIGH; // the current state of the output pin
int buttonState1; // the current reading from the input pin
int buttonState2; // the current reading from the input pin
int lastButtonState1 = LOW; // the previous reading from the input pin
int lastButtonState2 = LOW;
// 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 lastDebounceTime1 = 0; // the last time the output pin was toggled
long lastDebounceTime2 = 0; // the last time the output pin was toggled
long debounceDelay1 = 50; // the debounce time; increase if the output flickers
long debounceDelay2 = 50; // the debounce time; increase if the output flickers
void setup() {
pinMode(buttonPin1, INPUT);
pinMode(ledPin1, OUTPUT);
pinMode(buttonPin2, INPUT);
pinMode(ledPin2, OUTPUT);
}
void loop() {
// read the state of the switch into a local variable:
int reading1 = digitalRead(buttonPin1);
int reading2 = digitalRead(buttonPin2);
// 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 (reading1 != lastButtonState1) {
// reset the debouncing timer
lastDebounceTime1 = millis();
}
if (reading2 != lastButtonState2) {
// reset the debouncing timer
lastDebounceTime2 = millis();
}
if ((millis() - lastDebounceTime1) > debounceDelay1) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
buttonState1 = reading1;
}
if ((millis() - lastDebounceTime2) > debounceDelay2) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
buttonState2 = reading2;
}
// set the LED using the state of the button:
digitalWrite(ledPin1, buttonState1);
digitalWrite(ledPin2, buttonState2);
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
lastButtonState1 = reading1;
lastButtonState2 = reading2;
}