Heres is a snippet of code i was just working on:
EDIT: By request here is the full code (sorry for not realizing)
int LedPINS [] = {10,9,8,7,6,5,4,3};
boolean TLightRed = false;
int button = 2, buttonState = 0;//button test
unsigned long previousMillis=0;
void setup() {
// initialize the digital pin as an output.
for (int i = 0; i < 8; i++ )
{
pinMode(LedPINS[i],OUTPUT); // loop through each LED Output
}
}
void loop() {
if(TLightRed == false|| TLightRed == true) { // if red traffic light is one or off
digitalWrite(LedPINS[1],HIGH);//Turn on appropriate lights
digitalWrite(LedPINS[7],HIGH);
digitalWrite(LedPINS[2],HIGH);
if ((unsigned long)(millis() - previousMillis) > 500) {
previousMillis = millis();
digitalWrite(LedPINS[3],HIGH);
digitalWrite(LedPINS[2],LOW); // THIS LED LIGHT DOES NOT TURN OFF!!!
previousMillis=0;
if ((unsigned long)(millis() - previousMillis) > 6777) {
//previousMillis = millis();
digitalWrite(LedPINS[3],LOW); //turn on appropriate lights
digitalWrite(LedPINS[4],HIGH);
digitalWrite(LedPINS[4],LOW);
previousMillis=0;
}
}
Any input would be much appreciated!
GiftsAwait:
Heres is a snippet...
And here is another...
http://snippets-r-us.com/
GiftsAwait:
Heres is a snippet of code i was just working on:
EDIT: By request here is the full code (sorry for not realizing)
int LedPINS [] = {10,9,8,7,6,5,4,3};
boolean TLightRed = false;
int button = 2, buttonState = 0;//button test
unsigned long previousMillis=0;
void setup() {
// initialize the digital pin as an output.
for (int i = 0; i < 8; i++ )
{
pinMode(LedPINS[i],OUTPUT); // loop through each LED Output
}
}
void loop() {
if(TLightRed == false|| TLightRed == true) { // if red traffic light is one or off
digitalWrite(LedPINS[1],HIGH);//Turn on appropriate lights
digitalWrite(LedPINS[7],HIGH);
digitalWrite(LedPINS[2],HIGH);
if ((unsigned long)(millis() - previousMillis) > 500) {
previousMillis = millis();
digitalWrite(LedPINS[3],HIGH);
digitalWrite(LedPINS[2],LOW); // THIS LED LIGHT DOES NOT TURN OFF!!!
previousMillis=0;
if ((unsigned long)(millis() - previousMillis) > 6777) {
//previousMillis = millis();
digitalWrite(LedPINS[3],LOW); //turn on appropriate lights
digitalWrite(LedPINS[4],HIGH);
digitalWrite(LedPINS[4],LOW);
previousMillis=0;
}
}
Any input would be much appreciated!
You are missing two right curly braces, meaning that your code will not compile. We can't know for sure where they should be, and where they are may be your problem. Care to repost the code?
Compile it. If it doesn't compile, change it until it does.
Then press CTRL-T to format the code.
Then paste it between code tags.
Regardless of whether or not it compiles, your first if statement is useless, It will always enter the block of code that writes a HIGH to pins 1, 2, and 7. Think about it. if TLightRed is true, enter the if. OR if TLightRed is false enter the if.
The other two if statements, if they ever execute, will turn LEDs off.
However, the very next time through loop(), you will turn them all on again, regardless of the condition of TLightRed.
Bottom line, if your LEDs ever turn off, they will be back on quicker than you can see.