Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your task is to build a simplified traffic light (TL) controller using the ESP32 board and the provided set of sensors. The TL comprises three

Your task is to build a simplified traffic light (TL) controller using the ESP32 board and the provided set of sensors. The TL comprises three LEDs, a buzzer, and a touch button.

Problem description:

The TL goes from green through yellow to red, and from red through red-yellow to green. The TL remains in red for 10 seconds.

The TL remains in yellow and red-yellow for 2 seconds.

The TL has a touch button for pedestrians, it remains in green until the pedestrian button is pressed. The TL remains in green at least 5 seconds after the touch button has become active.

The TL has a buzzer for visual impairment aid with two modes. When in green the buzzer must be 500 ms on and 1500 ms off; when in red the buzzer must be 250 ms on and 250 ms off. (NOTE: You can put a fingertip on the top of the buzzer to reduce the sound volume)

Hint:

The system can be modeled as a 4-state state machine: RED, RED-YELLOW, YELLOW, and GREEN.

A possible basic structure for the application is shown next.

#define RED_PIN 32 #define YELLOW_PIN 33 #define GREEN_PIN 25

// Hard coded enumerator #define RED_STATE 0 #define RED_YELLOW_STATE 1 #define YELLOW_STATE 2 #define GREEN_STATE 3

#define RED_MILLIS 10000

int tl_state; // Traffic light state. unsigned long tl_timer; // Traffic light timer. void setup() { // Configure LED pins as outputs. pinMode(RED_PIN, OUTPUT); pinMode(YELLOW_PIN, OUTPUT); pinMode(GREEN_PIN, OUTPUT);

// Initial state for states and timers.. tl_state = RED_STATE;

tl_timer = millis() + RED_MILLIS; }

void loop() { // TL state machine switch (tl_state) { case RED_STATE: // Turn red light on. if (/*Timer expired*/) { // Turn red light off.

// Set timer for red-yellow state. tl_state = RED_YELLOW_STATE; } break; case RED_YELLOW_STATE: // Code for red-yellow state. break; case YELLOW_STATE: // Code for yellow state. break; case GREEN_STATE: // Turn green light on. if (/*Timer expired AND touch-button was pressed*/) { // Turn green light off.

// Set timer for yellow state. tl_state = YELLOW_STATE; } break; } // Detect touch - button pressed. // Buzzer state machine. // . // . }

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

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions

Question

2. What potential barriers would you encourage Samuel to avoid?

Answered: 1 week ago