// The traffic light's pins const int RED_PIN = 11; const int YELLOW_PIN = 10; const int GREEN_PIN = 9; // How long each light stays on (ms) const unsigned long RED_TIME = 5000; const unsigned long YELLOW_TIME = 2000; const unsigned long GREEN_TIME = 5000; void setup() { pinMode(RED_PIN, OUTPUT); pinMode(YELLOW_PIN, OUTPUT); pinMode(GREEN_PIN, OUTPUT); Serial.begin(9600); } // Sets all three lights: HIGH is on void lights(int red, int yellow, int green) { digitalWrite(RED_PIN, red); digitalWrite(YELLOW_PIN, yellow); digitalWrite(GREEN_PIN, green); } void loop() { // Stop: red only lights(HIGH, LOW, LOW); Serial.println("Red: stop"); delay(RED_TIME); // Get ready: red and yellow together lights(HIGH, HIGH, LOW); Serial.println("Red + yellow: get ready"); delay(YELLOW_TIME); // Go: green only lights(LOW, LOW, HIGH); Serial.println("Green: go"); delay(GREEN_TIME); // Caution: yellow only lights(LOW, HIGH, LOW); Serial.println("Yellow: caution, stopping"); delay(YELLOW_TIME); }