Hey all,
You guys helped me cross the finish line with one of the arduino lessons I was trying to expand on in the last topic I posted, hopefully you can help again. I have two problems on this one.
The Setup:
Simulating a traffic light with a CA RGB led, three tactile switches, and a leonardo.
redSwitchPin, LOW fires a green light, followed by yellow delayed, and then solid red.
greenSwitchPin, LOW is supposed to turn the solid red to greenLEDPin, LOW - Not working for some reason, the code looks good but im not sure what im doing wrong that the greenSwitchPin does nothing when pressed.
failSwitchPin, LOW is supposed to simulate when a traffic light has failed and the red light just blinks. This works but a nested loop needs to be added to run indefinitely until another event (switch press) has occurred.
I researched nested loops and found some info on forLoop and While commands but not really sure how to implement them to create an indefinite loop within a loop until a switch command stops it.
And then of course the second problem why the greenSwitchPin commands are being completely ignored in the code.
Here is the code
int redLEDPin = 11;
int greenLEDPin = 10;
int blueLEDPin = 9;
int redSwitchPin = 6;
int greenSwitchPin = 5;
int failSwitchPin = 3;
void setup()
{
pinMode(redLEDPin, OUTPUT);
pinMode(greenLEDPin, OUTPUT);
pinMode(blueLEDPin, OUTPUT);
pinMode(redSwitchPin, INPUT_PULLUP);
pinMode(greenSwitchPin, INPUT_PULLUP);
pinMode(failSwitchPin, INPUT_PULLUP);
digitalWrite (redLEDPin, LOW);
digitalWrite (greenLEDPin, HIGH);
digitalWrite (blueLEDPin, HIGH);
}
void loop()
{
if (digitalRead(redSwitchPin) == LOW)
{
digitalWrite (blueLEDPin, HIGH);
digitalWrite (redLEDPin, HIGH);
digitalWrite (greenLEDPin, LOW);
delay (3000);
digitalWrite (redLEDPin, LOW);
delay (3000);
digitalWrite (greenLEDPin, HIGH);
}
if (digitalRead(greenLEDPin) == LOW)
{
digitalWrite (blueLEDPin, HIGH);
digitalWrite (redLEDPin, HIGH);
digitalWrite (greenLEDPin, LOW);
}
if (digitalRead(failSwitchPin) == LOW)
{
digitalWrite (blueLEDPin, HIGH);
digitalWrite (redLEDPin, LOW);
delay (2000);
digitalWrite (redLEDPin, HIGH);
delay (2000);
}
}
Any input would be awesomeness on your part,
Just trying to learn,
Mike