Hi everyone iv tried to add a second push button to this code but my result is not correct, all i get is both the outputs being activated from second button input pin have tried finding where iv gone wrong for weeks now getting a bit frustrated now i know its probably really simple but if someone could please help i would really appreciate it thanks in advance. there are heaps of tutorials and documentation on how to do one button circuits but i can't seem to find any on how to have more than one button
/* switch
*
- Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
- press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's
- a minimum delay between toggles to debounce the circuit (i.e. to ignore
- noise).
- David A. Mellis
- 21 November 2006
*/
int inPin = 2; // the number of the input pin
int outPin = 3; // the number of the output pin
int inPinA = 8; //the number of the input pinA
int outPinA = 9; //the number of the ouput pinA
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(inPinA, INPUT);
pinMode(outPinA, OUTPUT);
}
void loop()
{
reading = digitalRead(inPin);
reading = digitalRead(inPinA);
// 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(outPin, state);
digitalWrite(outPinA, state);
previous = reading;
}