Presenter Guide: Build a CodyNick Temperature Alarm
Session goal
Build one program in seven small steps. The audience first sees how easily Python can control a physical LED, then gradually adds blinking, a display, a sensor, temperature colors, an alarm melody, and a joystick alarm control.
Do not paste the final program at the beginning. Type each step live, run it, invite the audience to predict the result, and then change the existing program for the next step.
Equipment
- Raspberry Pi running CodyNick
- CodyJoy Pro
- Temperature sensor
- CodyJoy Pro seven-segment display
- Python IDE at
http://10.42.0.1/code/
Presentation rhythm
For every step:
- Ask the engaging question before showing the new code.
- Let the audience suggest an answer.
- Type the small change.
- Ask the audience to predict the result.
- Select Run This File and observe the hardware and live terminal.
Step 1: Light One RGB LED
Ask before starting
How many lines of Python do you think we need to control a real LED?
Explain that CodyNick.CN() creates the connection and LED number 0 is the first LED
on the RGB matrix. A color is written as red, green, and blue values in hexadecimal.
import time
import CodyNick
cody = CodyNick.CN()
try:
if not cody.ensure_connected():
raise RuntimeError("CodyNick gadget not found.")
CodyNick.RGB_Matrix.set(cody, 0, "#00FF00")
time.sleep(3)
finally:15)
CodyNick.RGB_Matrix.clear(cody)
cody.close()
Point out
0selects the first LED.#00FF00means green.time.sleep(3)keeps it visible for three seconds.finallyturns the LEDs off even when an error occurs.
Step 2: Make the LED Blink
Ask before starting
A computer follows instructions very quickly. How can we make it wait long enough for our eyes to see an LED blink?
Replace the single LED command and three-second wait with this loop:
import time
import CodyNick
cody = CodyNick.CN()
try:
if not cody.ensure_connected():
raise RuntimeError("CodyNick gadget not found.")
for count in range(5):
CodyNick.RGB_Matrix.set(cody, 0, "#00FF00")
time.sleep(0.5)
CodyNick.RGB_Matrix.set(cody, 0, "#000000")
time.sleep(0.5)
finally:
CodyNick.RGB_Matrix.clear(cody)
cody.close()
Point out
range(5)repeats the indented instructions five times.#000000means no red, green, or blue, so the LED is off.- The two half-second waits create an obvious rhythm.
Invite the audience to predict what changing 0.5 to 0.1 will do.
Step 3: Show a Fixed Number
Ask before starting
If Python can control one light, can it also send a complete number to a display with one instruction?
Replace the blinking code with a seven-segment display command:
import time
import CodyNick
cody = CodyNick.CN()
try:
if not cody.ensure_connected():
raise RuntimeError("CodyNick gadget not found.")
CodyNick.Seven_Segment.display(cody, "CJP", 25)
time.sleep(3)
finally:
CodyNick.Seven_Segment.display(cody, "CJP", "")
cody.close()
Point out
"CJP"selects the CodyJoy Pro display.25is the value sent to the display.- Sending an empty string clears the display during cleanup.
Step 4: Show a Counter
Ask before starting
The display is showing data from our program. What should change if we want the display to show progress instead of one fixed value?
Change the fixed display command to a loop:
import time
import CodyNick
cody = CodyNick.CN()
try:
if not cody.ensure_connected():
raise RuntimeError("CodyNick gadget not found.")
for number in range(10):
CodyNick.Seven_Segment.display(cody, "CJP", number)
print("Count:", number)
time.sleep(1)
finally:
CodyNick.Seven_Segment.display(cody, "CJP", "")
cody.close()
Point out
range(10)produces the numbers0through9.- The same variable is shown on the physical display and in the live terminal.
- Software variables can directly represent real-world output.
Step 5: Display the Measured Temperature
Ask before starting
So far, Python has displayed numbers that we chose. How can the physical world choose the number instead?
Replace the counter with a continuous sensor loop:
import time
import CodyNick
cody = CodyNick.CN()
try:
if not cody.ensure_connected():
raise RuntimeError("CodyNick gadget not found.")
while True:
temperature = CodyNick.Temperature_Sensor.read(cody)
temperature = round(temperature, 1)
CodyNick.Seven_Segment.display(cody, "CJP", temperature)
print("Temperature:", temperature, "C")
time.sleep(1)
finally:
CodyNick.Seven_Segment.display(cody, "CJP", "")
cody.close()
Point out
read(cody)gets a current measurement from the sensor.round(..., 1)keeps one digit after the decimal point.while Truecontinues until the presenter stops the script.- The one-second pause gives a readable update rate.
Ask someone to gently warm the sensor and watch the number respond.
Step 6: Add Temperature Colors
Ask before starting
Can someone understand whether a temperature is cold, comfortable, or hot more quickly from a number or from a color?
Add the temperature decision and use a loop to color all 16 LEDs:
import time
import CodyNick
cody = CodyNick.CN()
try:
if not cody.ensure_connected():
raise RuntimeError("CodyNick gadget not found.")
while True:
temperature = CodyNick.Temperature_Sensor.read(cody)
temperature = round(temperature, 1)
CodyNick.Seven_Segment.display(cody, "CJP", temperature)
if temperature < 18:
color = "#0000FF"
elif temperature <= 30:
color = "#00FF00"
else:
color = "#FF0000"
for led in range(16):
CodyNick.RGB_Matrix.set(cody, led, color)
print("Temperature:", temperature, "C")
time.sleep(1)
finally:
CodyNick.RGB_Matrix.clear(cody)
CodyNick.Seven_Segment.display(cody, "CJP", "")
cody.close()
Point out
- Below 18 C is blue.
- From 18 C through 30 C is green.
- Above 30 C is red.
if,elif, andelseturn one measurement into one of three decisions.range(16)applies the chosen color to the complete matrix.
Step 7: Add the Alarm and Joystick Inhibit
Ask before starting
A real alarm may need to be silenced while someone investigates. How can one joystick button act as both the silence control and the re-enable control?
Start with two state variables before try:
alarm_enabled = True
was_clicked = False
Then build the final program:
import time
import CodyNick
cody = CodyNick.CN()
alarm_enabled = True
was_clicked = False
try:
if not cody.ensure_connected():
raise RuntimeError("CodyNick gadget not found.")
while True:
temperature = CodyNick.Temperature_Sensor.read(cody)
temperature = round(temperature, 1)
CodyNick.Seven_Segment.display(cody, "CJP", temperature)
if temperature < 18:
color = "#0000FF"
elif temperature <= 30:
color = "#00FF00"
else:
color = "#FF0000"
for led in range(16):
CodyNick.RGB_Matrix.set(cody, led, color)
is_clicked = CodyNick.Joystick.click(cody, "CJP")
if is_clicked and not was_clicked:
alarm_enabled = not alarm_enabled
if alarm_enabled:
print("Alarm enabled")
else:
print("Alarm inhibited")
was_clicked = is_clicked
if temperature > 30 and alarm_enabled:
CodyNick.CJP_Sound_Maker.play_until_done(cody, "C6", 120)
CodyNick.CJP_Sound_Maker.play_until_done(cody, "E6", 120)
CodyNick.CJP_Sound_Maker.play_until_done(cody, "G6", 120)
CodyNick.CJP_Sound_Maker.play_until_done(cody, "E6", 120)
print(
"Temperature:",
temperature,
"C - Alarm:",
"enabled" if alarm_enabled else "inhibited"
)
time.sleep(0.3)
finally:
CodyNick.RGB_Matrix.clear(cody)
CodyNick.Seven_Segment.display(cody, "CJP", "")
cody.close()
Point out
alarm_enabledremembers whether sound is permitted.was_clickedallows one physical press to cause only one toggle.not alarm_enabledchanges enabled to inhibited and inhibited to enabled.- The red visual warning remains active while the audible alarm is inhibited.
- The alarm melody is
C6,E6,G6,E6. - The joystick is checked between complete melody cycles.
Closing audience questions
- Which thresholds would you use for a refrigerator, greenhouse, or classroom?
- What other sensor could replace the temperature sensor?
- What could the joystick control besides the alarm?
- How could the dashboard or cloud record the temperature history?
Presenter reminder
Keep the code visible while demonstrating the hardware response. The purpose is not to memorize every command; it is to show the repeated pattern:
- Read an input.
- Make a decision.
- Control an output.
- Repeat safely.