| Date | |
|---|---|
13 March 2026 |
Assigned |
20 March 2026 |
Due |
| Progress |
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 -> Greencycle - a less standard
Red -> Offcycle- standard, of course, if you grew up in a small town with only one stoplight
- a less common, but not uncommong
Yellow -> Offcycle- 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!
This assignment addresses the following course learning objective(s):
- Apply Python programming fundamentals to execute and explain computer code that implements interactive, novel solutions to a variety of computable problems.
- Implement code consistent with industry-standard practices using professional-grade integrated development environments (IDEs), command-line tools, and version control systems.
- Analyze and suggest revisions to existing Python language code to add functionality or repair defects.
- 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.
- Design, describe, and implement original projects incorporating industry-standard practices and Python language fundamentals.
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
2wires- breadboard
3resistors3LEDs
| 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.
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_timeoutsto set the timeouts of various lightsset_patternto createON/OFFpatterns of the lightsreset_lightswhich responds to a button press by:- turning all lights
ONat the same time for1second - turning all lights
OFF, allowing the device to proceed to the next mode or to end the program
- turning all lights
Important
To complete this assignment, you will need to implement the above modes in order (i.e., Normal, "Midnight", "Yield").
This function requires a dictionary input such as:
# For three lights
{"red": 3, "yellow": 3, "green": 3}
# For one light
{"red": 3, "off": 3}This function requires a list input such as:
# For three lights
["red", "yellow", "green"]
# For one light
["red", "off"]This function requires no explicit input, but must:
- turn all lights on at once
- turn off all lights to indicate resetting
The hardware (the Raspberry Pi Pico) relies on some fundamental structures:
PinsPin.INPin.OUT
sleep
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 (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()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 |
Your programming will be evaluated on the following characteristics:
- Program produces all three modes in the order described:
- Normal mode
- "Midnight" mode
- "Yield" mode
- Program executes each of the cycles independently
- Program sets timeouts as expected
- Program can set and execute arbitrary light timeouts and patterns
The output for this program relies on external LEDs to validate outputs/outcomes.
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.
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.