I do apologize if this has been answered i did look around for a while and i do feel like i may have run across the answer but the question was never asked directly. My code (which is pretty much a copy of a tutorial i found on the site) just re written works as intended but when ever i try to add a 2nd tact switch to control a 2nd LED it wont compile. i apologize for being a noob. I have only had my Arduino UNO for about a week. But i am learning a lot and learning coding a lot faster this way than trying to make hello world programs not to mention learning electronics at the same time.
//Debounce
long time = 0;
long debounce = 200;
//Brake LightsVariables
int brakeLed = 7;
int brakeButton = 12;
int brakeState = LOW;
int brakeStateprev = HIGH;
int brakeRead;
void setup()
{
//Brake Light Pins
pinMode(brakeLed, 1);
pinMode(brakeButton, 0);
}
void loop()
{
//Brake Light loop
brakeRead = digitalRead(brakeButton);
if (brakeRead == HIGH && brakeStateprev == LOW && millis() - time > debounce) {
if (brakeState == HIGH)
brakeState = LOW;
else
brakeState = HIGH;
time = millis();
}
digitalWrite(brakeLed, brakeState);
brakeStateprev = brakeRead;
}
This was the original code that i tried to get to work. The only difference is that it has my attempt at adding the 2nd switch, variable names and the organization. Thank you in advance for any help.
int inPin1 = 12;
int outPin1 = 6;
int inPin2 = 11;
int outPin2 = 5;
int state1 = LOW;
int reading1;
int previous1 = HIGH;
int state2 = LOW;
int reading2;
int previous2 = HIGH;
long time1 = 0;
long debounce1 = 200;
long time2 = 0;
long debounce2 = 200;
void setup()
{
pinMode(inPin1, INPUT);
pinMode(outPin1, OUTPUT);
pinMode(inPin2, INPUT);
pinMode(outPin2, OUTPUT);
void loop()
{
reading1 = digitalRead(inPin1);
if (reading1 == HIGH && previous1 == LOW && millis() - time1 > debounce1) {
if (state1 == HIGH)
state1 = LOW;
else
state1 = HIGH;
time1 = millis();
}
if (reading2 == HIGH && previous2 == LOW && millis() - time2 > debounce2) {
if (state2 == HIGH)
state2 = LOW;
else
state2 = HIGH;
time2 = millis();
}
digitalWrite(outPin1, state1);
previous2 = reading2;
digitalWrite(outPin2, state2);
previous2 = reading2;
}
Setting the previous2 from reading2 does not make much sense to me if nothing changed in between, but other than that, I can't guess what the error might be. Especially when reading2 is never even initialized.. previous1 never changes state either.
Sorry, forgot to paste ;]
sketch_feb19c.ino: In function 'void setup()':
sketch_feb19c:29: error: a function-definition is not allowed here before '{' token
sketch_feb19c:61: error: expected `}' at end of input
StrikerXero:
Sorry, forgot to paste ;]
sketch_feb19c.ino: In function 'void setup()':
sketch_feb19c:29: error: a function-definition is not allowed here before '{' token
sketch_feb19c:61: error: expected `}' at end of input