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

bg contain

Components

  • 1 RGB LEDs
  • MicroOLED
  • 3 x 330 Ohm resistors

Wiring Pin Guide

RGB LED Argon Pins
NorthSouth RGB LED - Red D2
NorthSouth RGB LED - Green D3
NorthSouth RGB LED - Blue D4
MicroOLED (Qwiic cable) Argon 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: