// Define LED pins for each direction
const int eastRedPin = 4;
const int eastYellowPin = 3;
const int eastGreenPin = 2;
const int southRedPin = 7;
const int southYellowPin = 6;
const int southGreenPin = 5;
const int westRedPin = 10;
const int westYellowPin = 9;
const int westGreenPin = 8;
const int northRedPin = 13;
const int northYellowPin = 12;
const int northGreenPin = 11;
// Timing constants (in milliseconds)
const int greenDuration = 5000; // Duration for green light
const int yellowDuration = 2000; // Duration for yellow light
void setup() {
// Initialize all pins as OUTPUT
pinMode(northRedPin, OUTPUT);
pinMode(northYellowPin, OUTPUT);
pinMode(northGreenPin, OUTPUT);
pinMode(southRedPin, OUTPUT);
pinMode(southYellowPin, OUTPUT);
pinMode(southGreenPin, OUTPUT);
pinMode(westRedPin, OUTPUT);
pinMode(westYellowPin, OUTPUT);
pinMode(westGreenPin, OUTPUT);
pinMode(eastRedPin, OUTPUT);
pinMode(eastYellowPin, OUTPUT);
pinMode(eastGreenPin, OUTPUT);
}
void loop() {
// North Yellow, South, West, East Red
setLights(LOW, HIGH, LOW, // North Yellow
LOW, LOW, HIGH, // South Red
LOW, LOW, HIGH, // West Red
LOW, LOW, HIGH); // East Red
delay(yellowDuration);
// North Green, South, West, East Red
setLights(HIGH, LOW, LOW, // North Green
LOW, LOW, HIGH, // South Red
LOW, LOW, HIGH, // West Red
LOW, LOW, HIGH); // East Red
delay(greenDuration);
// South Yellow, North, West, East Red
setLights(LOW, LOW, HIGH, // North Red
LOW, HIGH, LOW, // South Yellow
LOW, LOW, HIGH, // West Red
LOW, LOW, HIGH); // East Red
delay(yellowDuration);
// South Green, North, West, East Red
setLights(LOW, LOW, HIGH, // North Red
HIGH, LOW, LOW, // South Green
LOW, LOW, HIGH, // West Red
LOW, LOW, HIGH); // East Red
delay(greenDuration);
// West Yellow, North, South, East Red
setLights(LOW, LOW, HIGH, // North Red
LOW, LOW, HIGH, // South Red
LOW, HIGH, LOW, // West Yellow
LOW, LOW, HIGH); // East Red
delay(yellowDuration);
// West Green, North, South, East Red
setLights(LOW, LOW, HIGH, // North Red
LOW, LOW, HIGH, // South Red
HIGH, LOW, LOW, // West Green
LOW, LOW, HIGH); // East Red
delay(greenDuration);
// East Yellow, North, South, West Red
setLights(LOW, LOW, HIGH, // North Red
LOW, LOW, HIGH, // South Red
LOW, LOW, HIGH, // West Red
LOW, HIGH, LOW); // East Yellow
delay(yellowDuration);
// East Green, North, South, West Red
setLights(LOW, LOW, HIGH, // North Red
LOW, LOW, HIGH, // South Red
LOW, LOW, HIGH, // West Red
HIGH, LOW, LOW); // East Green
delay(greenDuration);
}
void setLights(int northGreen, int northYellow, int northRed,
int southGreen, int southYellow, int southRed,
int westGreen, int westYellow, int westRed,
int eastGreen, int eastYellow, int eastRed) {
// Set North direction lights
digitalWrite(northGreenPin, northGreen);
digitalWrite(northYellowPin, northYellow);
digitalWrite(northRedPin, northRed);
// Set South direction lights
digitalWrite(southGreenPin, southGreen);
digitalWrite(southYellowPin, southYellow);
digitalWrite(southRedPin, southRed);
// Set West direction lights
digitalWrite(westGreenPin, westGreen);
digitalWrite(westYellowPin, westYellow);
digitalWrite(westRedPin, westRed);
// Set East direction lights
digitalWrite(eastGreenPin, eastGreen);
digitalWrite(eastYellowPin, eastYellow);
digitalWrite(eastRedPin, eastRed);
}