State Machines Part 2 - Stoplight Example
State Machines
In class Exercise - Stoplight and Pedestrian Signal
In class Lab - Stoplight and Pedestrian Signal
- We are going to build a stoplight and pedestrian signal for a intersection.
- Car traffic goes North-South.
- Pedstrian traffic goes East-West
- Green lights, red lights, and the walk signal will stay on for 5 sec (
LONG_LIGHT_DURATION
) - Yellow lights and the don’t walk signal will stay on for 2 sec (
SHORT_LIGHT_DURATION
) - Here is how this type of intersection works
##
##
##
##
##
In class Exercise - Stoplight and Pedestrian Signal
- Download starting code
- Go to https://bit.ly/ProjectZip
- Paste the following link into the top right
https://github.com/reparke/ITP348-Physical-Computing/tree/main/_exercises/week07/stop_light_rgb_leds_oled_start
- Wire device as shown below
Wiring Diagram
Components
- 1 RGB LEDs
- MicroOLED
- 3 x 330 Ohm resistors
Wiring Pin Guide
RGB LED | Photon 2 Pins |
---|---|
NorthSouth RGB LED - Red | A2 |
NorthSouth RGB LED - Green | A5 |
NorthSouth RGB LED - Blue | D15 (MO) |
MicroOLED (Qwiic cable) | Photon 2 Pins |
---|---|
GND | GND |
3V3 | 3V3 |
SDA (Blue) | SDA |
SCL (Yellow) | SCL |
Lab Stages
-
Create cycle with only traffic (North-South) stop lights
-
Add Pedestrian Walk / Don’t Walk (East-West) message to OLED
-
Make Don’t Walk light blink when it is on (if time)
- We will work through stage 1 together
General Approach
- We will need to create a way to represent the states using
enum
- We will need to track state transitions with variables for state
-
We will need to control timing with
millis()
- What does
loop()
do- calculate new state
- output traffic signal LEDs based on state
- independently flash walk signal (later)
Credits
- Bill Siever - CS132 FSM (Washington University at St. Louis)
- Bill Siever - CS132 Delta Timing (Washington University at St. Louis)
- USC EE109 State Machines
- Photo by Laurie Parke
- Photo by Michael Olsen</a> on Unsplash
- Photo by Free To Use Sounds on Unsplash
- Photo by NON on Unsplash