STARLEAP / SPIKE PRIME PYTHON / 2026–27

Build 2026.09.22-090630-0400

On this page

Project 01: Hub Signal Board

You need: a LEGO SPIKE Prime set, its hub, and the SPIKE App Python editor. No robot build is needed yet.

Make a reusable start signal: a message, two pictures, a pause, and sound. Build one small working piece before adding the next.

Part 1 - Connect And Find The Hardware

Turn on the hub, open a Python project in the SPIKE App, connect the hub, and name the project Signal Board. Find the light matrix, left and right buttons, speaker, and lettered ports. Find one motor and one sensor in the set.

Hardware is the physical equipment. Software is the program you write. An import gives your program a name for a tool it can use.

Part 2 - Start With One Message

Type this starter program. Keep the four spaces before await.

CODE
from hub import light_matrix
import runloop

async def main():
    await light_matrix.write("Hi")

runloop.run(main())

Run the program. The hub should scroll Hi.

async def main(): names the chunk that will run. The indented line belongs to main. await waits for the message to finish. The final line starts main; it belongs at the left edge.

Edit - Change The Message

Change only the text inside the quotes. Gray lines show code already in your program; do not type them again or type the ~ marker from the Markdown source.

EDIT VIEW · Gray = already there; dark = add or change
async def main():
    await light_matrix.write("GO")

runloop.run(main())

Run the program. The hub should scroll GO. Point to the exact text you changed.

Fix it: if nothing scrolls, check the connection and the final runloop.run(main()) line. Match the capitalization in light_matrix exactly.

Part 3 - Give Images Time

Already completed the early hub work? First run the starter from Part 2 to prove your setup, then continue here.

Step 1 - Show Two Images

Replace only the whole main() definition with this version. Keep the imports above and runloop.run(main()) below it.

EDIT VIEW · Gray = already there; dark = add or change
async def main():
    light_matrix.show_image(light_matrix.IMAGE_ANGRY)
    light_matrix.show_image(light_matrix.IMAGE_HAPPY)

Run the program. The happy face should appear. The first image may change too quickly for you to see.

Step 2 - Add One Pause

Add the dark line between the two images. It has the same four-space indent as the image lines.

EDIT VIEW · Gray = already there; dark = add or change
async def main():
    light_matrix.show_image(light_matrix.IMAGE_ANGRY)
    await runloop.sleep_ms(2000)
    light_matrix.show_image(light_matrix.IMAGE_HAPPY)

Run the program. The angry face should stay for two seconds before the happy face appears. Change only 2000 to 500, then run the program again. What changed?

Step 3 - Finish With A Blank Screen

Add these two dark lines after the happy face, still inside main().

EDIT VIEW · Gray = already there; dark = add or change
    light_matrix.show_image(light_matrix.IMAGE_HAPPY)
    await runloop.sleep_ms(1000)
    light_matrix.clear()

Run the program. Both faces should be visible in order, then the screen should clear.

Fix it: leading spaces show which chunk owns a line. All five actions inside main() start four spaces in. Keep the start call at the left edge, outside that chunk.

Part 4 - Hear Two Sound Tools

App sounds play through the computer or tablet. A hub beep plays through the hub. Both modules are called sound, so give each one a clear name with as.

Step 4 - Add An App Sound

Add the dark import at the top of the file.

EDIT VIEW · Gray = already there; dark = add or change
from hub import light_matrix
from app import sound as app_sound
import runloop

Inside main(), add a sound before the screen clears.

EDIT VIEW · Gray = already there; dark = add or change
    await runloop.sleep_ms(1000)
    await app_sound.play("Triumph")
    light_matrix.clear()

Run the program. Listen at the computer or tablet. If the signal is silent, check its volume and the exact sound name in the SPIKE App sound list.

Step 5 - Add A Hub Beep

Add the dark import beside the other imports.

EDIT VIEW · Gray = already there; dark = add or change
from app import sound as app_sound
from hub import sound as hub_sound
import runloop

Add the beep immediately after the app sound, inside main().

EDIT VIEW · Gray = already there; dark = add or change
    await app_sound.play("Triumph")
    await hub_sound.beep(440, 500, 100)
    light_matrix.clear()

Run the program. Listen for the app sound, then a half-second beep on the hub. The beep values control pitch, duration in milliseconds, and volume.

Step 6 - Tune One Value

Change only 440 to 660, then run the program. Keep the duration and volume unchanged. Explain which part of the sound changed.

Part 5 - Give A Value A Name

A variable is a name attached to a value. It lets you tune the signal in one easy-to-find place.

Step 7 - Name The Pause

Add the dark line after the imports and before main(), at the left edge.

EDIT VIEW · Gray = already there; dark = add or change
import runloop

wait_time = 1000

async def main():

Replace the pause between the two images with the variable name. Do not put quotes around wait_time.

EDIT VIEW · Gray = already there; dark = add or change
    light_matrix.show_image(light_matrix.IMAGE_ANGRY)
    await runloop.sleep_ms(wait_time)
    light_matrix.show_image(light_matrix.IMAGE_HAPPY)

Run the program. The first image should stay for one second. Change the value stored in wait_time to 2000, then run the program again.

Step 8 - Name A Message

Add message beside wait_time, then add the write line as the first action inside main().

EDIT VIEW · Gray = already there; dark = add or change
wait_time = 2000
message = "GO"

async def main():
    await light_matrix.write(message)
    light_matrix.show_image(light_matrix.IMAGE_ANGRY)

Run the program. The text should scroll before the images. Change only the value of message, then run the program again.

Physical Challenge - Reusable Start Signal

Keep a short message, two visible images, an app sound, and a hub beep. Tune one value at a time. For a stretch, name the sound with sound_name = "Triumph" and pass that variable to app_sound.play(sound_name).

Teacher Check

Show the whole signal. Point to one import, one variable, and the line that uses that variable. Explain which sound comes from each device and how the pause changes your signal.

Save your program. Stop it and keep your place for next time.