STARLEAP / SPIKE PRIME PYTHON / 2026–27

Build 2026.09.22-090630-0400

On this page

Project 13: Coach Dance Reps

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

Goal

Use loops and timing to make a repeated physical routine.

Build

Build The Coach, Leo, or Break Dancer from the LEGO SPIKE Prime building instructions.

This packet uses The Coach:

Change the labels if your build uses different ports.

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: One Dance Move

Open a new Python project named Dance Reps.

Start with this short code:

CODE
from hub import port
import runloop
import motor

left_foot = port.F
right_foot = port.B
time_ms = 250
speed = 300

async def main():
    motor.run(right_foot, speed)
    motor.run(left_foot, speed)
    await runloop.sleep_ms(time_ms)

    motor.run(right_foot, -speed)
    motor.run(left_foot, -speed)
    await runloop.sleep_ms(time_ms)
    motor.stop(right_foot)
    motor.stop(left_foot)

runloop.run(main())

Run the program.

Observe: Both feet move together, then move back.

Step 2: Repeat It

Put the dance move inside a loop:

EDIT VIEW · Gray = already there; dark = add or change
async def main():
    for rep in range(5):
        motor.run(right_foot, speed)
        motor.run(left_foot, speed)
        await runloop.sleep_ms(time_ms)

        motor.run(right_foot, -speed)
        motor.run(left_foot, -speed)
        await runloop.sleep_ms(time_ms)
        motor.stop(right_foot)
        motor.stop(left_foot)

Run the program.

Observe: The move repeats 5 times.

Step 3: Count Reps

Add this as the first line inside the loop, indented eight spaces:

EDIT VIEW · Gray = already there; dark = add or change
async def main():
    for rep in range(5):
        print(rep + 1)
        motor.run(right_foot, speed)

Run the program with the console open.

Observe: The console counts 1 through 5.

Step 4: Tune The Routine

Change one value at a time:

Run the program after each change.

Physical Challenge: Rep Show

Extra setup idea: Try Push Then Dance 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.