Below, you will see the first Python program you will write.
Необходимо е да се абонирате за FLLCasts.com, за да достъпите това видео
- #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:
- motor.run() - starts a motor at the speed written in the command until the program encounters a stop command
- motor.stop() - stops a motor
- 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.
Курсове и занятия включващи този Урок
Този Урок е използван в следните курсове и занятия.
Level A: Python Foundations – Robotics with LEGO SPIKE Prime
This is the first level of the LEGO Robotics Curriculum with Python, designed for students in grades 2, 3, and 4.
In this robot adventure, students learn to control robots using real Python code, while teachers guide them through their first steps in text-based programming. Throughout the level, students build a variety of LEGO SPIKE Prime robot models and program them to move, turn, and complete tasks with increasing precision.
Step by step, students learn how to read, understand, and write their own Python programs. Through fun and creative challenges, they bring their robots to life and discover how code can control movement, solve problems, and interact with the world. Along the way, they explore concepts such as navigation, obstacle avoidance, and sensor-based behavior.
The curriculum is designed to help teachers introduce programming in an engaging and approachable way while giving students plenty of opportunities to experiment, test ideas, and develop confidence in their coding skills.
By the end of the level, students apply everything they have learned in an exciting robotics competition. Using their own programs and robot designs, they complete missions on a competition field with boxes, putting their coding, engineering, and problem-solving skills to the test.
- 46
- 4:32
- 78
Lesson 1 - Beverage Assistant
Introduction
Many students start learning robotics because robots can do amazing things. They can move, react, and even help people with everyday tasks. From small robots working together to larger robots that assist humans, robotics helps turn creative ideas into real, working machines.
You will learn how to design, build, and program your own robots using LEGO SPIKE Prime and Python. To create more advanced robots later, we begin with simple ones. Simple doesn’t mean boring - many real robots today started as basic designs and still do very important work.
Step by step, you will learn how to read and write Python programs and use them to control your robot. You will complete fun challenges, like making a robot that can deliver an item - just like a robot server that brings food and returns to its starting point.
These are your first steps into the world of robotics and programming. With each lesson, you will build more advanced robots and discover how code can make machines move, think, and solve problems in exciting ways.

- 9
- 4
- 9
- 3d_rotation 1