Traffic Light

Traffic Light


Wiring Diagram

Getting Ready for the Program

Green Light

When the green light is on what is the state (HIGH or LOW) of the LED's?


Green LED: HIGH (On)

Yellow LED: LOW (Off)

Red LED: LOW (Off)

Yellow Light

When the yellow light is on what is the state (HIGH or LOW) of the LED's?


Green LED: LOW (Off)

Yellow LED: HIGH (On)

Red LED: LOW (Off)

Red Light

When the red light is on what is the state (HIGH or LOW) of the LED's?


Green LED: LOW (Off)

Yellow LED: LOW (Off)

Red LED: HIGH(On)

Try it yourself

Before looking at the finished code below try and write it yourself first!


void setup()

declare what pins you are using with pinMode()

void loop()

write the main code here by using digitalWrite() and delay()

use the light states above to help you

Program

void setup() {

  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);

}

void loop() {

    digitalWrite(8, HIGH);
    digitalWrite(9, LOW);
    digitalWrite(10, LOW);

    delay(1000);

    digitalWrite(8, LOW);
    digitalWrite(9, HIGH);
    digitalWrite(10, LOW);

    delay(1000);

    digitalWrite(8, LOW);
    digitalWrite(9, LOW);
    digitalWrite(10, HIGH);

    delay(1000);
}

Final Quiz