STM32 Traffic Control
Loading...
Searching...
No Matches
controller.h File Reference

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.

Detailed Description

Traffic Light Controller Public Interface.

This header defines the public interface for the traffic light controller module.

Macro Definition Documentation

◆ BUTTON1

#define BUTTON1   (1U<<10)

GPIO masks for the buttons.

◆ BUTTON2

#define BUTTON2   (1U<<11)

◆ BUTTON3

#define BUTTON3   (1U<<12)

◆ BUTTON4

#define BUTTON4   (1U<<13)

◆ BUTTONS

#define BUTTONS   4

Total number of buttons.

◆ DEBOUNCE_TIME

#define DEBOUNCE_TIME   100

Minimum debounce time for button press in milliseconds.

◆ MAX_WAITING_PAIR

#define MAX_WAITING_PAIR   2

Maximum number of waiting pairs.

Function Documentation

◆ changeLight()

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.

Parameters
lightAIndex of the first traffic light in the pair
lightBIndex of the second traffic light in the pair

◆ SysTick_CheckFirstPressTimeout()

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.

◆ SysTick_handleGreenPhaseTimeout()

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.

◆ SysTick_handleYellowTransitionTimeout()

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 YELLOW light pair is turned RED

The next waiting light pair is released to GREEN

The variable 'WaitingLightPair' indicates which light pair is waiting:

  • 0: Light pair 1-3
  • 1: Light pair 2-4

This funciton is called periodically by the SysTick_Handler.