Skip to content

ComputationalExpression/assignment-stoplight-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Building a Stoplight

Image

Date
13 March 2026 Assigned
20 March 2026 Due
Progress Grade

Our world is filled with wonderful electronic objects: including stoplights! In this lab, you'll build a stoplight with 3 modes:

  • a standard Red -> Yellow -> Green cycle
  • a less standard Red -> Off cycle
    • standard, of course, if you grew up in a small town with only one stoplight
  • a less common, but not uncommong Yellow -> Off cycle
    • typical when the power goes out or there's construction about

You'll need to keep an eye on this README, as it contains specifications for each mode and how the Stoplight object works. Not following the specs laid out here will cause the lab to work incorrectly!

Learning Objectives

This assignment addresses the following course learning objective(s):

  1. Apply Python programming fundamentals to execute and explain computer code that implements interactive, novel solutions to a variety of computable problems.
  2. Implement code consistent with industry-standard practices using professional-grade integrated development environments (IDEs), command-line tools, and version control systems.
  3. Analyze and suggest revisions to existing Python language code to add functionality or repair defects.
  4. Evaluate the practical and ethical implications of writing computer code and discuss the contexts, perceived effects, and impacts exerted on and by computer code as a cultural force or artifact.
  5. Design, describe, and implement original projects incorporating industry-standard practices and Python language fundamentals.

Pinout Diagram

Note

This is different from previous labs, as we're adding a few parts. You'll need to follow the pinout below exactly to make testing work.

The above graphic is a pinout diagram: a description of how to wire a physical computing project. Match the above diagram with the following components:

  • push button
  • Raspberry Pi Pico
  • 2 wires
  • breadboard
  • 3 resistors
  • 3 LEDs
Pins Purpose
15 Button
16 Green light
17 Yellow light
18 Red light

Important

The above writing is critical to the code. We address specific parts during our programs. Make sure it matches. If you have questions, ask a TL or the instructor!

: indicates that a resistor must exist between the light and the pin.

Summary of the problem

Important

In order to run the program in this lab, you'll need to do the following when you've made the appropriate changes:

uv run mpremote cp src/Stoplight.py :

As you will make changes in this file to create a functional Stoplight, you'll need to do this each time the file changes!

Our Stoplight must implement the 3 modes described above. The following is a description of these modes.

Mode Description
Normal The light cycles R->Y->G each after 3 seconds.
Midnight The light cycles R->OFF each after 3 seconds.
Yield The light cycles Y->OFF each after 3 seconds.

This program must implement:

  • set_timeouts to set the timeouts of various lights
  • set_pattern to create ON/OFF patterns of the lights
  • reset_lights which responds to a button press by:
    • turning all lights ON at the same time for 1 second
    • turning all lights OFF, allowing the device to proceed to the next mode or to end the program

Important

To complete this assignment, you will need to implement the above modes in order (i.e., Normal, "Midnight", "Yield").

set_timeouts

This function requires a dictionary input such as:

# For three lights
{"red": 3, "yellow": 3, "green": 3}
# For one light
{"red": 3, "off": 3}

set_pattern

This function requires a list input such as:

# For three lights
["red", "yellow", "green"]
# For one light
["red", "off"]

reset_lights

This function requires no explicit input, but must:

  • turn all lights on at once
  • turn off all lights to indicate resetting

Implementing hardware

The hardware (the Raspberry Pi Pico) relies on some fundamental structures:

  • Pins
    • Pin.IN
    • Pin.OUT
  • sleep

Pins

Pins represent physical pins on the Raspberry Pi Pico device which can be either inputs or outputs. Our button is an input: Pin(16, Pin.IN); our LED is an on-board output: Pin("LED", Pin.OUT).

As a general rule, 0 indicates a press, and 1 indicates the button is not being pressed.

LEDs

LEDs (lights) required Pin.OUT modes. For example, to program the RED light. To turn these on and off, use the on and off methods of the Pin.

# Turns light ON
self.lights[light].on()
# Turns light OFF
self.lights[light].off()

Evaluation

Note

To grade this lab, use the uv run gatorgrade command.

Labs in this course are each worth 5 points. You are awarded different levels of points using the following rubric:

Component Value
Programming 2
Code Review 2
Writing 1
Total 5

Programming

Your programming will be evaluated on the following characteristics:

  • Program produces all three modes in the order described:
  1. Normal mode
  2. "Midnight" mode
  3. "Yield" mode
  • Program executes each of the cycles independently
  • Program sets timeouts as expected
  • Program can set and execute arbitrary light timeouts and patterns

Expected output

The output for this program relies on external LEDs to validate outputs/outcomes.

Code review

Either a Technical Leader TL or the instructor can perform a code review with you. This must be done before the due date for the assignment. You may accomplish this during a lab session, TL office hours, or during the instructor's office hours. Successful completion of this review (and an accompanying successful outcome) will earn points toward the code review portion of the assignment.

Writing

Students are expected to finish a summary document. This is a Markdown file containing questions. All questions must be answered fully. Typically, this means a word count is assessed.

For this assignment, the minimum required word count is 150.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages