State Machines Part 2 - Stoplight Example

State Machines

In class Exercise - Stoplight and Pedestrian Signal

stoplight ped_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

##

bg contain ##

bg contain

##

bg contain ##

bg contain

##

In class Exercise - Stoplight and Pedestrian Signal

  • Download starting code

    https://github.com/reparke/ITP348-Physical-Computing/tree/main/_exercises/week07/stop_light_rgb_leds_oled_start

  • Wire device as shown below

Wiring Diagram

Screenshot 2024-06-19 at 12.07.42 PM

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

  1. Create cycle with only traffic (North-South) stop lights

  2. Add Pedestrian Walk / Don’t Walk (East-West) message to OLED

  3. 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

Updated: