STARLEAP / SPIKE PRIME PYTHON / 2026–27

Build 2026.09.22-090630-0400

On this page

Project 11: Kiki Color Station

You need: a LEGO SPIKE Prime set and the SPIKE App Python editor.

Goal

Make Kiki react differently to different colors.

Build

Build Kiki, the Dog, or another model with the color sensor pointed outward.

Starting port:

Use blue, green, red, yellow, or magenta LEGO pieces as color cards.

Using the code: gray lines are already in your program; dark lines are the edit. Keep the shown indentation. Replace a displayed main() definition as a whole, keeping imports and the final start call.

What You Will Learn

Step 1: Blue Or Not Blue

Open a new Python project named Kiki Color.

Start with this short code:

CODE
from hub import port
import runloop
import color_sensor
import color
from app import sound

color_port = port.A

def get_color():
    return color_sensor.color(color_port)

async def main():
    current_color = get_color()

    if current_color == color.BLUE:
        await sound.play("Bird")
        print("blue")
    else:
        await sound.play("Dog Bark 1")
        print("not blue")

runloop.run(main())

Run the program with a blue piece, then with a different color.

Observe: Blue gets one reaction. Other colors get the other reaction.

Step 2: Add Green

Add this between the if and else:

EDIT VIEW · Gray = already there; dark = add or change
    if current_color == color.BLUE:
        await sound.play("Bird")
        print("blue")
    elif current_color == color.GREEN:
        await sound.play("Cat Angry")
        print("green")
    else:
        await sound.play("Dog Bark 1")
        print("not blue")

Run the program with blue, green, and one other color.

Observe: You now have three paths.

Step 3: Keep Checking

Change main():

EDIT VIEW · Gray = already there; dark = add or change
async def main():
    while True:
        current_color = get_color()

        if current_color == color.BLUE:
            await sound.play("Bird")
            print("blue")
        elif current_color == color.GREEN:
            await sound.play("Cat Angry")
            print("green")
        else:
            print("not blue or green")

        await runloop.sleep_ms(1000)

Run the program.

Observe: Kiki checks again after each sound finishes and a one-second pause.

Physical Challenge: Color Station

One player shows a color. Kiki must react without anyone touching the keyboard.

Extra setup idea: Try Color Stop Lines from the Challenge Setups sheet.

Teacher Check

Show your teacher:

Before You Put The Kit Away

Save your program. Stop the program before moving wires or changing the build. Show the teacher your working behavior, point to one changed line, and explain what it controls. Keep your place for next time.