Your first program in Python for SPIKE Pro Preview

Below, you will see the first Python program you will 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)


Below, you will see the first Python program you will write.

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 motor commands, we first need to tell the program that we will use them. We do this by writing the following at the beginning of the program:

import motor

Similarly, to use the wait command "time.sleep_ms()", we need to tell the program that we will use it:

import time

To make the code shorter and easier to write, we can simply use:

import motor, time

Motor commands need to know which port is being used. You can use the port number, but using the "port" keyword makes the code easier to read. To use this keyword, we need to tell the program that we will use it:

from hub import port

You will notice that this import looks different from the others. This is because instead of importing the entire "hub" module, we are importing only the "port" keyword.

One advantage of this is that we don’t need to write "hub.port". We can simply use "port" in our commands, which makes the code shorter and easier to read.