Question
If anyone is experienced in Arduino add a pushbutton with your traffic lights to simulate a pedestrian crossing. When the pushbutton is pressed it should
If anyone is experienced in Arduino
add a pushbutton with your traffic lights to simulate a pedestrian crossing. When the pushbutton is pressed it should wait until the traffic light turns red and then it should turn the pedestrian light green for 8 seconds, it should blink green for 2 seconds and then turn red. It will then resume normal traffic light operation.
Example:
Traffic lights are running normally
Pedestrian presses button (keep pressing until red light on traffic lights)
Traffic lights are both red
Pedestrian lights turn green for 8 seconds
Pedestrian lights blink green for 2 seconds
Pedestrian lights turn red
Traffic lights resume running normally.
=============================
Here is the code for the traffic light:
const int redPin = 8; const int yellowPin = 7; const int greenPin = 6; const int red2 = 13; const int yellow2 = 12; const int green2 = 11;
void setup() { // setting pin to out[ut pinMode(redPin, OUTPUT); pinMode(yellowPin, OUTPUT); pinMode(greenPin, OUTPUT);
pinMode(red2, OUTPUT); pinMode(yellow2, OUTPUT); pinMode(green2, OUTPUT); }
void loop() { // First traffic light sequence: red to red and yellow to green digitalWrite(redPin, HIGH); digitalWrite(yellowPin, LOW); digitalWrite(greenPin, LOW); digitalWrite(green2, HIGH); delay(5000); digitalWrite(redPin, HIGH); digitalWrite(yellowPin, HIGH); digitalWrite(greenPin, LOW); digitalWrite(yellow2, HIGH); digitalWrite(green2, LOW); delay(2000);
digitalWrite(redPin, LOW); digitalWrite(yellowPin, LOW); digitalWrite(greenPin, HIGH); digitalWrite(yellow2, LOW); digitalWrite(green2, LOW); digitalWrite(red2, HIGH); delay(4000);
// Second traffic light sequence: green to yellow to red digitalWrite(redPin, LOW); digitalWrite(yellowPin, LOW); digitalWrite(greenPin, HIGH); digitalWrite(red2, HIGH); digitalWrite(yellow2, LOW); digitalWrite(green2, LOW); delay(5000);
digitalWrite(redPin, LOW); digitalWrite(yellowPin, HIGH); digitalWrite(greenPin, LOW); digitalWrite(red2, HIGH); digitalWrite(yellow2, HIGH); digitalWrite(green2, LOW); delay(2000);
digitalWrite(redPin, HIGH); digitalWrite(yellowPin, LOW); digitalWrite(greenPin, LOW); digitalWrite(red2, LOW); digitalWrite(yellow2, LOW); digitalWrite(green2, HIGH); delay(3000);
digitalWrite(redPin, LOW); digitalWrite(yellowPin, LOW); digitalWrite(greenPin, LOW); digitalWrite(red2, LOW); digitalWrite(yellow2, LOW); digitalWrite(green2, LOW); delay(1000);
}
Add 2 lights one green and one red, connect with the pushbutton and then code it with the question above.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started