How to add a cross walk timer to a 4 way traffic light controller?

So i have already made the 4 way traffic light controller using the code below, but was wondering how to add a cross walk timer using a 7 segment display to it, any advice will help thanks:

int signal1[] = {1, 5, 9};
int signal2[] = {2, 6, 10};
int signal3[] = {3, 7, 11};
int signal4[] = {4, 8, 12};

int redDelay = 5000;
int yellowDelay = 2000;

void setup() {
// Declaring all the LED's as output
for (int i = 0; i < 3; i++) {
pinMode(signal1*, OUTPUT);*
_ pinMode(signal2*, OUTPUT);_
_ pinMode(signal3, OUTPUT);
pinMode(signal4, OUTPUT);
}
}
void loop() {
// Making Green LED at signal 1 and 3 and red LED's at other signal HIGH*

* digitalWrite(signal1[2], HIGH);
digitalWrite(signal1[0], LOW);
digitalWrite(signal2[0], HIGH);
digitalWrite(signal3[2], HIGH);
digitalWrite(signal4[0], HIGH);
delay(redDelay);*_

* // Making Green LED at signal 1 and 3 LOW and making yellow LED at signal 1 and signal 3 HIGH for 2 seconds*
* digitalWrite(signal1[1], HIGH);*
* digitalWrite(signal1[2], LOW);*
* digitalWrite(signal3[1], HIGH);*
* digitalWrite(signal3[2], LOW);*
* delay(yellowDelay);*
* digitalWrite(signal1[1], LOW);*
* digitalWrite(signal3[1], LOW);*

* // Making Green LED at signal 2 and 4 and red LED's at other signal HIGH*
* digitalWrite(signal1[0], HIGH);*
* digitalWrite(signal2[2], HIGH);*
* digitalWrite(signal2[0], LOW);*
* digitalWrite(signal3[0], HIGH);*
* digitalWrite(signal4[2], HIGH);*
* digitalWrite(signal4[0], LOW);*
* delay(redDelay);*

* // Making Green LED at signal 2 and 4 LOW and making yellow LED at signal 2 and 4 HIGH for 2 seconds*
* digitalWrite(signal2[1], HIGH);*
* digitalWrite(signal2[2], LOW);*
* digitalWrite(signal4[1], HIGH);*
* digitalWrite(signal4[2], LOW);*
* delay(yellowDelay);*
* digitalWrite(signal2[1], LOW);*
digitalWrite(signal4[1], LOW);
}

And now with code tags, please.

If you want a countdown, do it where you currently have delays.

Srry im really new to this stuff what is a code tag?

The usual behavior for a crosswalk timer is that the pedestrian presses a button to signal that they want the crossing signal. When this is pressed, a flag is set in the software that controls the button. At an appointed time in the cycle, it checks if this flag is set, and if it is, it clears the flag and shows the walksignal and countdown, so the drivers waiting at the intersection know how long they have to swear and make rude gestures at the pedestrian (who already got tired of waiting and crossed without the signal, because they had to wait through the whole light cycle), or to look at their phones (just kidding, the drivers do this while they're moving anyway). If the flag isn't set at this point, it skips that step.

Probably wants to be done using blink-without-delay techniques (millis() for timing and a state machine), since if you're using delay, it can't check whether the button is pressed while it's sitting there delaying (there's a way one could do it with delay and an interrupt on the button, but this is considerably harder than what I described and worse practice)

Khaleel_Ali:
Srry im really new to this stuff what is a code tag?

Try the "how to use this forum" thread...

Khaleel_Ali:
Srry im really new to this stuff what is a code tag?

Makes the code much easier to read.