int a=14;   //GPIO14 >>>  D5
int b=4;    //GPIO4 >>>   D4
int c=1;    //GPIO1 >>>   D1
int d=16;   //GPIO16 >>>  D2
int e=5;    //GPIO5 >>>   D3
int f=12;   //GPIO12 >>>  D6
int g=13;   //GPIO13 >>>  D7
                          
int ledR = 15;//GPIO15 >>>  D10
int ledY = 2; //GPIO2 >>>   D9
int ledG = 0; //GPIO0 >>>   D8

//Display number 1
void digital_1(void)
{
  digitalWrite(a,LOW);
  digitalWrite(b,HIGH);
  digitalWrite(c,HIGH);
  digitalWrite(d,LOW);
  digitalWrite(e,LOW);
  digitalWrite(f,LOW);
  digitalWrite(g,LOW);
}
//Display number 2
void digital_2(void)
{
  digitalWrite(a,HIGH);
  digitalWrite(b,HIGH); 
  digitalWrite(c,LOW); 
  digitalWrite(d,HIGH);
  digitalWrite(e,HIGH);
  digitalWrite(f,LOW);
  digitalWrite(g,HIGH);
}
//Display number 3
void digital_3(void)
{
  digitalWrite(a,HIGH);
  digitalWrite(b,HIGH); 
  digitalWrite(c,HIGH); 
  digitalWrite(d,HIGH);
  digitalWrite(e,LOW);
  digitalWrite(f,LOW);
  digitalWrite(g,HIGH);
}

//Display number 4
void digital_4(void)
{
  digitalWrite(a,LOW);
  digitalWrite(b,HIGH); 
  digitalWrite(c,HIGH); 
  digitalWrite(d,LOW);
  digitalWrite(e,LOW);
  digitalWrite(f,HIGH);
  digitalWrite(g,HIGH);
}
//Display number 5
void digital_5(void)
{
  digitalWrite(a,HIGH);
  digitalWrite(b,LOW); 
  digitalWrite(c,HIGH); 
  digitalWrite(d,HIGH);
  digitalWrite(e,LOW);
  digitalWrite(f,HIGH);
  digitalWrite(g,HIGH);
}
//Display number 6
void digital_6(void)
{
  digitalWrite(a,HIGH);
  digitalWrite(b,LOW);
  digitalWrite(c,HIGH);
  digitalWrite(d,HIGH);
  digitalWrite(e,HIGH);
  digitalWrite(f,HIGH);
  digitalWrite(g,HIGH);
}
//Display number 7
void digital_7(void)
{
  digitalWrite(a,HIGH);
  digitalWrite(b,HIGH); 
  digitalWrite(c,HIGH);
  digitalWrite(d,LOW);
  digitalWrite(e,LOW);
  digitalWrite(f,LOW);
  digitalWrite(g,LOW);
}

//Display number 8
void digital_8(void)
{
  digitalWrite(a,HIGH);
  digitalWrite(b,HIGH); 
  digitalWrite(c,HIGH); 
  digitalWrite(d,HIGH);
  digitalWrite(e,HIGH);
  digitalWrite(f,HIGH);
  digitalWrite(g,HIGH);
}
//Display number 9
void digital_9(void)
{
  digitalWrite(a,HIGH);
  digitalWrite(b,HIGH); 
  digitalWrite(c,HIGH); 
  digitalWrite(d,HIGH);
  digitalWrite(e,LOW);
  digitalWrite(f,HIGH);
  digitalWrite(g,HIGH);
}
//Pin setting and initialization
void setup() 
{
  pinMode(a,OUTPUT);
  pinMode(b,OUTPUT);
  pinMode(c,OUTPUT);
  pinMode(d,OUTPUT);
  pinMode(e,OUTPUT);
  pinMode(f,OUTPUT);
  pinMode(g,OUTPUT);
  pinMode(ledR,OUTPUT);
  pinMode(ledG,OUTPUT);
  pinMode(ledY,OUTPUT);
}

void loop() 
{
  while(1)
  {
    //red light
    digitalWrite(ledR,LOW);
    digitalWrite(ledY,HIGH);
    digitalWrite(ledG,HIGH);

    digital_9();  // Show 9
    delay(1000);   //Delay 1 s
    digital_8();  // Show 8
    delay(1000);   //Delay 1 s 
    digital_7();  // Show 7 
    delay(1000);   //Delay 1 s
    digital_6();  // Show 6 
    delay(1000);   //Delay 1 s
    digital_5();  // Show 5 
    delay(1000);   //Delay 1 s
    digital_4();  // Show 4 
    delay(1000);   //Delay 1 s
    digital_3();  // Show 3 
    delay(1000);   //Delay 1 s
    digital_2();  // Show 2 
    delay(1000);   //Delay 1 s
    digital_1();  // Show 1 
    delay(1000);   //Delay 1 s
    //green light
    digitalWrite(ledR,HIGH);
    digitalWrite(ledY,HIGH); 
    digitalWrite(ledG,LOW);

    digital_9();  // Show 9 
    delay(1000);   //Delay 1 s
    digital_8();  // Show 8
    delay(1000);   //Delay 1 s
    digital_7();  // Show 7 
    delay(1000);   //Delay 1 s
    digital_6();  // Show 6 
    delay(1000);   //Delay 1 s
    digital_5();  // Show 5 
    delay(1000);   //Delay 1 s
    digital_4();  // Show 4 
    delay(1000);   //Delay 1 s
    digital_3();  // Show 3 
    delay(1000);   //Delay 1 s
    digital_2();  // Show 2 
    delay(1000);   //Delay 1 s
    digital_1();  // Show 1 
    delay(1000);   //Delay 1 s
    //yellow light
    digitalWrite(ledR,HIGH);
    digitalWrite(ledY,LOW);
    digitalWrite(ledG,HIGH);
    digital_3();  // Show 3 
    delay(1000);   //Delay 1 s
    digital_2();  // Show 2 
    delay(1000);   //Delay 1 s
    digital_1();  // Show 1 
    delay(1000);   //Delay 1 s
  }
}
