Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2008 Comprehensive Concepts And Techniques

Authors: Gary B. Shelly, Corinne Hoisington

1st Edition

1423927168, 978-1423927167

More Books

Students also viewed these Databases questions

Question

3. Are our bosses always right? If not, what should we do?

Answered: 1 week ago