So I have this small project with a traffic system (T-intersection) with small features.
I worked out the timing for the LEDs on one sketch and the photoresistor-depended LED on another.
My problem starts with working the photoresistor in parallel with the traffic light. I know that delay(); causes the arduino to completely stop, so how should I make them work in parallel? so that the photoresistor-depended LED will work independently from the traffic light system?
code for traffic light
void setup() {
pinMode(13, OUTPUT); // red horizontal (A)
pinMode(12, OUTPUT); // yellow horizontal (A)
pinMode (11, OUTPUT); // green horizontal (A)
pinMode(10, OUTPUT); // red vertical (B)
pinMode(9, OUTPUT); // yellow vertical (B)
pinMode (8, OUTPUT);// green vertical (B)
pinMode (7,OUTPUT); // pedestrian red
pinMode (6,OUTPUT); // pedestrian green
}void loop() {
digitalWrite(13, HIGH); // red A on
digitalWrite(8, HIGH); // green B on
digitalWrite (7,HIGH); // pedestrian red on
delay(10000);
digitalWrite(8, LOW); // green B off
digitalWrite (9,HIGH); // yellow B on
digitalWrite (7,LOW);// pedestrian red off
digitalWrite (6,HIGH); //pedestrian green on
delay (5000);
digitalWrite(13, LOW); // red A off
digitalWrite (11,HIGH); // green A on
digitalWrite(9, LOW); // yellow B off
digitalWrite (10, HIGH); //red B on
delay (10000);
digitalWrite (11,LOW); // green A off
digitalWrite (12,HIGH );// yellow A on
delay (5000);
digitalWrite(12, LOW);//yellow A off
digitalWrite (6,LOW); //pedestrian green off
}