/*
Interview project for Lexington Medical
Prepared 2025-10-27
STM32 Arduino Core (stm32duino)
Specification:
1. With no use of the crosswalk button the traffic lights should cycle between
red/yellow/green per the following sequence:
13 seconds: Mass Ave Green, Beacon St Red
2 seconds: Mass Ave Yellow, Beacon St Red
13 seconds: Mass Ave Red, Beacon St Green
2 seconds: Mass Ave Red, Beacon St Yellow
2. If ever both traffic lights are red, pedestrian light can be green,
otherwise pedestrian light should be red.
3. If the crosswalk button is pressed then whichever traffic light is
currently green (or yellow) should transition if needed to the yellow
state and then after finishing the 2 second yellow state, both traffic
lights should be red for 20 seconds before resuming green on whichever
traffic light holds the longest elapsed time since last being green.
4. Once the crosswalk button has been pressed, further presses should be
queued until one full cycle has finished (meaning 20 seconds for the
pedestrian cycle and 60 seconds for one full traffic cycle).
For reference guides see https://docs.wokwi.com/
*/
extern "C" {
#include "traffic_ctrl.h"
}
// Pin map per diagram.json
constexpr uint8_t PIN_MASS_AVE_RED = A0;
constexpr uint8_t PIN_MASS_AVE_YELLOW = A1;
constexpr uint8_t PIN_MASS_AVE_GREEN = A2;
constexpr uint8_t PIN_BEACON_ST_RED = A5;
constexpr uint8_t PIN_BEACON_ST_YELLOW = A6;
constexpr uint8_t PIN_BEACON_ST_GREEN = A7;
constexpr uint8_t PIN_PED_RED = A3;
constexpr uint8_t PIN_PED_GREEN = A4;
constexpr uint8_t PIN_BTN = PB0; // active-low, use pull-up
void setup() {
pinMode(PIN_MASS_AVE_RED, OUTPUT);
pinMode(PIN_MASS_AVE_YELLOW, OUTPUT);
pinMode(PIN_MASS_AVE_GREEN, OUTPUT);
pinMode(PIN_BEACON_ST_RED, OUTPUT);
pinMode(PIN_BEACON_ST_YELLOW, OUTPUT);
pinMode(PIN_BEACON_ST_GREEN, OUTPUT);
pinMode(PIN_PED_RED, OUTPUT);
pinMode(PIN_PED_GREEN, OUTPUT);
pinMode(PIN_BTN, INPUT_PULLUP); // active-low
Serial.begin(115200);
Serial.println("BOOT: dual-road TL controller");
// Perform one time setup here
digitalWrite(PIN_PED_RED, true);
Serial.println("");
Serial.println("Example: pedestrian light set to red");
Serial.println("Good luck, have fun!");
}
void loop() {
// Call periodic functions on your traffic controller code from here
//test comment
//test comment 2
}