Hi folks,
I'm new to this forum and still a novice in Arduino programming, pardon me if I am unable to understand some of the terms ![]()
There's this project involving a traffic light system which uses 4 outputs, RED light, AMBER light, GREEN light & RIGHT TURN light.
The programming sequence:
- RED ON for 1 second
- RED switches to GREEN, GREEN ON for 10 seconds
- GREEN switches to AMBER, AMBER ON for 2 seconds
- AMBER switches to RED, RED ON for 1 seconds
- RED switches to GREEN & RIGHT TURN, both ON for 4 seconds
- GREEN switches to AMBER and AMBER ON, RIGHT TURN starts to blink 3 times, with 1 second OFF 1 second ON(ON OFF ON OFF ON OFF)
- AMBER OFF and RIGHT TURN BLINK OFF
- Repeat step 1 again
I have no problem with any of the sequence except with the RIGHT TURN blink. The thing is, I am suppose to use only the Millis function to perform the blinking. I had a clue which said I have to use the following code below, but just where to place it is the problem.
const int ledPin=13;
int ledState=0;
long previousMillis=0;
long interval=1000; //1 second interval
void setup()
{
pinMode(ledPin,OUTPUT);
}
void loop()
{
unsigned long currentMillis=millis();
if(currentMillis - previousMillis > interval)
{
-
previousMillis=currentMillis;*
-
if(ledState==0)*
-
ledState=1;*
-
else*
-
ledState=0;*
-
digitalWrite(ledPin, ledState);*
}
}
Please enlighten me on this issue. Do let me know if there's anything not understandable. Any other alternative code suggestions will be welcomed too. Quite an urgent matter.
Thanks in advance