Digispark (5) Traffic light

3灯式信号機のスケッチです。

PB0:デジタル出力0 ー Green LED.
PB1:デジタル出力1 ー Yellow LED.
PB2:デジタル出力2 ー Red LED.
PB3:デジタル出力3 ー GND
PB4:デジタル出力4
PB5:デジタル出力5

//Traffic light toy sketch for DigiSpark. by: Hong Chen.

#define PINGND      3
#define PINRed      2
#define PINYel      1
#define PINGre      0

void setup() {
  pinMode(PINGND, OUTPUT);
  digitalWrite(PINGND, LOW);
  pinMode(PINRed, OUTPUT); //Red LED.
  pinMode(PINYel, OUTPUT); //Yellow LED.
  pinMode(PINGre, OUTPUT); //Green LED. 
}

//Looping forever
void loop() {
  digitalWrite(PINRed, HIGH); // Turn on red LED.
  delay(3000); //Waits for 3 sec.
  
  digitalWrite(PINYel, HIGH); //Turn on yellow LED.
  delay(2000); //Waits for 2 sec.

  digitalWrite(PINRed, LOW); //Turn off red LED.
  digitalWrite(PINYel, LOW); //Turn off yellow LED.
  digitalWrite(PINGre, HIGH); //Turn on green LED.
  delay(5000); //Waits for 5 sec.
  
  digitalWrite(PINGre, LOW); //Turn off green LED.
  digitalWrite(PINYel, HIGH); //Turn on yellow LED.
  delay(2000); //Waits for 2 sec.
  
  digitalWrite(PINYel, LOW); //Turn off yellow LED.
}

 

Leave a Reply

Your email address will not be published.