Your first program in Python for SPIKE Pro Preview

In the program below, you will see the first program you'll write.

To access the full video please subscribe to FLLCasts.com

Subscribe

  • #2579
  • 26 Jan 2026
import runloop
from hub import port
import motor, time

async def main():
    # write your code here
    motor.run(port.E, 1000)
    motor.run(port.F, 1000)
    time.sleep_ms(2000)
    motor.stop(port.E)
    motor.stop(port.F)

runloop.run(main())

The commands used are as follows:

  1. motor.run() - starts a motor at the speed written in the command until the program encounters a stop command
  2. motor.stop() - stops a motor
  3. time.sleep_ms() - pauses the program for a set number of milliseconds. 1000 milliseconds are equal to 1 second.

To use the motor commands, we need to tell the program that we'll be using them by writing the following at the beginning of the program:

import motor

Similarly, to use the wait command "time.sleep_ms()" we need to warn the program that we'll be using it:

import time

To save space, we can simply write:

import motor, time

The motor commands require knowing which port is being used. You can write the number for the port, but we found that using the "port" keyword makes the program more readable. To use this keyword, we need to do the same as before and warn the program that we are using this tool:

from hub import port

You'll notice that this import does not look like the rest. That is because instead of importing the full "hub" module, we are importing only the "port" keyword. One of the advantages of this method is that we won't need to write "hub.port" but rather just the "port" part of the command.