#include "ArduinoTrace.h"
const int pinR = 5;
const int pinY = 3;
const int pinG = 2;
bool R,G,Y;
//======================== SETUP ===========================//
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(pinR, OUTPUT);
pinMode(pinY, OUTPUT);
pinMode(pinG, OUTPUT);
}
//======================== LOOP ===========================//
void loop() {
// put your main code here, to run repeatedly:
static unsigned long pm=0;
if((millis()-pm)>=100)
{
pm=millis();
Task1();
}
}
//======================== TASK1 ===========================//
void Task1()
{
static int step=1;
static int counter=0;
switch (step)
{
case 1: //INIT
G=1;
digitalWrite(pinG, HIGH);
counter=50;
step=2;
break;
case 2: //G_ON
counter--;
if(counter==0)
{
G=0;
digitalWrite(pinG, LOW);
Y=1;
digitalWrite(pinY, HIGH);
counter=20;
step=3;
}
break;
case 3: //Y_ON
counter--;
if(counter==0)
{
Y=0;
digitalWrite(pinY, LOW);
R=1;
digitalWrite(pinR, HIGH);
counter=40;
step=4;
}
break;
case 4: //R_ON
counter--;
if(counter==0)
{
Y=1;
digitalWrite(pinY, HIGH);
counter=20;
step=5;
}
break;
case 5: //R_ON Y_ON
counter--;
if(counter==0)
{
Y=0;
digitalWrite(pinY, LOW);
R=0;
digitalWrite(pinR, LOW);
G=1;
digitalWrite(pinG, HIGH);
counter=50;
step=2;
}
break;
}
DUMP(step);
DUMP(millis()/1000);
}
//========================================================//