|
STM32 Traffic Control
|
Traffic Light Controller Public Interface. More...
#include <stdio.h>#include <stdint.h>#include <stdbool.h>#include "stm32f446xx.h"Go to the source code of this file.
Macros | |
| #define | BUTTON1 (1U<<10) |
| GPIO masks for the buttons. | |
| #define | BUTTON2 (1U<<11) |
| #define | BUTTON3 (1U<<12) |
| #define | BUTTON4 (1U<<13) |
| #define | BUTTONS 4 |
| Total number of buttons. | |
| #define | DEBOUNCE_TIME 100 |
| Minimum debounce time for button press in milliseconds. | |
| #define | MAX_WAITING_PAIR 2 |
| Maximum number of waiting pairs. | |
Functions | |
| void | SysTick_handleGreenPhaseTimeout (void) |
| Monitor and handle expiration of the active GREEN light phase. | |
| void | SysTick_handleYellowTransitionTimeout (void) |
| Handle expiration of the YELLOW light phase for a traffic light pair. | |
| void | changeLight (uint32_t lightA, uint32_t lightB) |
| Switch the active traffic light pair. | |
| void | SysTick_CheckFirstPressTimeout (void) |
| Check for first button press timeout and process queued requests. | |
Traffic Light Controller Public Interface.
This header defines the public interface for the traffic light controller module.
| #define BUTTON1 (1U<<10) |
GPIO masks for the buttons.
| #define BUTTON2 (1U<<11) |
| #define BUTTON3 (1U<<12) |
| #define BUTTON4 (1U<<13) |
| #define BUTTONS 4 |
Total number of buttons.
| #define DEBOUNCE_TIME 100 |
Minimum debounce time for button press in milliseconds.
| #define MAX_WAITING_PAIR 2 |
Maximum number of waiting pairs.
| void changeLight | ( | uint32_t | lightA, |
| uint32_t | lightB ) |
Switch the active traffic light pair.
This function transitions the currently active traffic light pair from GREEN -> YELLOW -> RED, then releases the specified light pair to GREEN.
The GREEN light duration is dynamically calculated based on the highest car count detected between the two lights in the specified pair.
All timing is handled asychronously via the SysTick timer to avoid blocking delays.
| lightA | Index of the first traffic light in the pair |
| lightB | Index of the second traffic light in the pair |
| void SysTick_CheckFirstPressTimeout | ( | void | ) |
Check for first button press timeout and process queued requests.
This function checks if the 3-second window after the first button press has elapsed. If so, it queues the requested light pairs based on the order of button presses and processes the first request in the queue.
Resets the first and second press tracking variables after processing.
This function is called periodically by the SysTick_Handler.
| void SysTick_handleGreenPhaseTimeout | ( | void | ) |
Monitor and handle expiration of the active GREEN light phase.
This function checks whether the allocated GREEN duration for the currently active traffic light pair has elapsed. When the timer expires, the active light pair is released and the next queued light pair (if any) is dequeued and processed.
This funciton is called periodically by the SysTick_Handler.
| void SysTick_handleYellowTransitionTimeout | ( | void | ) |
Handle expiration of the YELLOW light phase for a traffic light pair.
This function checks whether the 1-second YELLOW duration for the currently waiting traffic light pair has elapsed. Once the timer expires:
The next waiting light pair is released to GREEN
The variable 'WaitingLightPair' indicates which light pair is waiting:
This funciton is called periodically by the SysTick_Handler.