Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!