Hallo, I tried a long time, but didn't find a solution. I want to use 2 buttons, each button controlls one led and change the actual status from High to low and Low to High with a push.
My actual code controls alway both leds no matter which button i push. Pls help me thx.
int inPin = 2; // the number of the input pin
int outPin = 13;
int inPin2 = 3; // the number of the input pin
int outPin2 = 12; // the number of the output pin
// the number of the output pin
int state = HIGH; // the current state of the output pin
int reading; // the current reading from the input pin
int previous = LOW; // the previous reading from the input pin
// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
void setup()
{
pinMode(inPin, INPUT);
pinMode(outPin, OUTPUT);
pinMode(inPin2, INPUT);
pinMode(outPin2, OUTPUT);
}
void loop()
{
reading = digitalRead(inPin);
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
else
state = HIGH;
time = millis();
}
digitalWrite(outPin2, state);
reading = digitalRead(inPin2);
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
else
state = HIGH;
time = millis();
}
digitalWrite(outPin2, state);
previous = reading;
}