Posted by admin on Jan 28, 2019
Arduino Traffic light

Arduino Traffic light

Arduino Traffic light.

Based on the Arduino functions seen this week, your mission is to write an Arduino sketch that will blink 3 virtual LEDs (green→pin 4, orange→pin 3, red→pin 2). This program will must abide by the following instructions:

  1. All the pins have to be set as OUTPUT at the beginning of the sketch
  2. The green LED (on pin 4) is switched on for 3 seconds (green LED will be the first to light up) then it is switched off
  3. When the green LED is switched off, orange LED is switched on for 1 seconds then it is switched off again
  4. When the orange LED is switched off, red LED is switched on for 3 seconds then it is switched off again
  5. These instructions must run again and again in the loop()!

 

Arduino Traffic light

Arduino Traffic light.

// S21H
// 1 second = 1000 millisecond

int (green) = 4; //D4 Pin = green
int (orange) = 3; //D3 Pin = orange
int (red) = 2; //D2 Pin = red

void setup() {

pinMode(green, OUTPUT); // Pin Condition declaration
pinMode(orange, OUTPUT); // Pin Condition declaration
pinMode(red, OUTPUT); // Pin Condition declaration

}

void loop() { //These instructions must run again and again in the loop()!

digitalWrite( green , HIGH); //The green LED (on pin 4) is switched on for 3 seconds
delay(3000);
digitalWrite(green, LOW);
delay(3000);

digitalWrite(orange, HIGH); //orange LED is switched on for 1 seconds
delay(1000);
digitalWrite(orange, LOW);
delay(1000);

digitalWrite(red, HIGH); // red LED is switched on for 3 seconds
delay(3000);
digitalWrite(red, LOW);
delay(3000);
}

 

 

Please follow and like us:
Post a Comment

Leave a Reply

Translate »
%d bloggers like this: