🎮 Welcome to Robot Programming!

What is Pybricks?

Imagine you have a robot friend who only understands a special language called Python. Pybricks is like a translator that helps you talk to your SPIKE Prime robot using Python!

👤 ➡️ 💻 ➡️ 🤖

You write code → Computer translates → Robot moves!

Think of programming like writing a recipe for your robot. Just like a recipe tells you step-by-step how to make cookies, your code tells the robot step-by-step what to do!

🎯 Let's Get Started!

✨ Ready to Code?

Before moving on, make sure:

✅ Your hub is connected

✅ You can see the code editor

✅ You're excited to learn!

🌟 Your First Robot Program

Let's Make Something Happen!

We're going to make your robot's light turn on! It's like teaching your robot to turn on a flashlight.

🎨 Make the Light Red
# This is your first program!
# Lines with # are comments - notes for humans

from pybricks.hubs import PrimeHub
from pybricks.parameters import Color
from pybricks.tools import wait

# Create your robot brain
hub = PrimeHub()

# Turn on the light (like a red stop light!)
hub.light.on(Color.RED)

# Wait 2 seconds (2000 milliseconds)
wait(2000)

# Turn off the light
hub.light.off()

print("Great job! You just programmed a robot!")
💡 Off → 🔴 Red (2 seconds) → 💡 Off

Your robot's light will do this!

🔬 Experiment Time!

What happens if you change Color.RED to Color.BLUE?

Click to see the answer!

The light will turn blue instead of red! Try Color.GREEN and Color.YELLOW too!

🎯 Try These Challenges!

🎉 Mission Complete!

You just wrote your first robot program! You're officially a robot programmer!

📦 Variables - Robot Memory Boxes

What are Variables?

Variables are like labeled boxes where your robot stores information. Just like you might have a toy box labeled "LEGOS", your robot has memory boxes with names!

my_speed
500
robot_name
"Speedy"
distance
100

Each box has a name and stores something inside!

📦 Creating Variables
# Store numbers
my_age = 12
robot_speed = 500

# Store words (called "strings")
robot_name = "Bolt"
favorite_color = "blue"

# Store yes/no values (called "booleans")
is_moving = True
lights_on = False

# Use your variables!
print("My robot's name is", robot_name)
print("It moves at speed", robot_speed)
Variables are like your backpack pockets! You put your pencil in the "pencil pocket" and your snack in the "snack pocket". Later, you know exactly where to find them!

🔬 Variable Math!

What will this print: speed = 100 then speed = speed + 50?

Click to see the answer!

It will print 150! The robot takes the old value (100) and adds 50 to it!

🎯 Variable Challenges!

🔄 Loops - Teaching Robots to Repeat

Why Use Loops?

Imagine you want your robot to blink its light 100 times. You could write the same code 100 times... or use a loop to do it automatically!

Loops are like instructions for brushing your teeth: "Move the brush up and down 20 times." You don't need 20 separate instructions - just one instruction to repeat!
Without Loop: 📝📝📝📝📝 (Write 5 times)
With Loop: 🔄 × 5 (Write once, repeat 5 times!)

Loops save time and make code cleaner!

🔄 For Loop - Count to 5
# Count from 1 to 5
for number in range(1, 6):
    print("Count:", number)
    hub.display.number(number)
    wait(1000)

print("Counting complete!")

# Blink the light 3 times
for i in range(3):
    hub.light.on(Color.GREEN)
    wait(500)
    hub.light.off()
    wait(500)
🔄 While Loop - Keep Going Until...
# Import Button from parameters first
from pybricks.parameters import Button

# Keep blinking until button is pressed
while Button.CENTER not in hub.buttons.pressed():
    hub.light.on(Color.BLUE)
    wait(200)
    hub.light.off()
    wait(200)

print("Button pressed - stopping!")

🔬 Loop Detective!

How many times will this loop run: for i in range(10)?

Click to see the answer!

10 times! When you use range(10), it counts from 0 to 9 (that's 10 numbers total).

🎯 Loop Challenges!

🤔 If Statements - Robot Decisions

Teaching Robots to Think!

Your robot needs to make decisions, just like you do! If it's raining, take an umbrella. If there's a wall, stop moving. Let's teach your robot to think!

Distance to wall?
< 10cm
🛑 STOP!
10-30cm
⚠️ Slow Down
> 30cm
✅ Full Speed!

Your robot makes different choices based on sensor readings!

🤔 Simple Decision
# Check the distance
distance = 25  # Pretend we measured this

if distance < 10:
    print("Too close! Stopping!")
    hub.light.on(Color.RED)
elif distance < 30:
    print("Getting close, be careful!")
    hub.light.on(Color.YELLOW)
else:
    print("All clear!")
    hub.light.on(Color.GREEN)
If statements are like a choose-your-own-adventure book! "If you want to explore the cave, turn to page 23. If you want to climb the mountain, turn to page 45."

🔬 Decision Detective!

What color will show if speed = 150 and we check if speed > 200?

Click to see the answer!

The else block will run because 150 is NOT greater than 200. The condition is False!

🎯 Decision Challenges!

🎯 Working with the Hub

The Light Matrix

Hub Lights and Display
from pybricks.hubs import PrimeHub
from pybricks.parameters import Color, Icon
from pybricks.tools import wait

hub = PrimeHub()

# Control the status light
hub.light.on(Color.RED)
wait(1000)
hub.light.blink(Color.BLUE, [500, 500])  # On 500ms, off 500ms
wait(3000)

# Display icons
hub.display.icon(Icon.HAPPY)
wait(1000)
hub.display.icon(Icon.HEART)

# Display numbers and text
hub.display.number(42)
wait(1000)
hub.display.char('A')
wait(1000)
hub.display.text('GO!')  # Scrolls across display

# Custom pixel art
hub.display.off()
hub.display.pixel(2, 2, 100)  # Center pixel at full brightness

Buttons and Speaker

Interactive Hub Features
from pybricks.parameters import Button

# Check button presses
while True:
    pressed = hub.buttons.pressed()
    
    if Button.LEFT in pressed:
        hub.speaker.beep(frequency=500)
    elif Button.RIGHT in pressed:
        hub.speaker.beep(frequency=1000)
    elif Button.CENTER in pressed:
        break  # Exit loop
    
    wait(100)

# Play musical notes
notes = ["C4/4", "D4/4", "E4/4", "F4/4", "G4/2"]
hub.speaker.play_notes(notes, tempo=120)

⚙️ Motors - Bringing Robots to Life!

What are Motors?

Motors are like the muscles of your robot! Just like your muscles help you move your arms and legs, motors help your robot move its parts.

🔄 Motor = Robot Muscle! 💪
⬅️ Backward
⏸️ Stop
➡️ Forward

Motors can spin forward, backward, or stop!

⚙️ Basic Motor Control
from pybricks.pupdevices import Motor
from pybricks.parameters import Port

# Connect your motor to Port A
my_motor = Motor(Port.A)

# Make it spin forward (positive number)
my_motor.run(500)  # 500 degrees per second
wait(2000)  # Keep spinning for 2 seconds

# Make it spin backward (negative number)
my_motor.run(-500)
wait(2000)

# Stop the motor
my_motor.stop()

# Spin exactly 3 times (3 × 360 degrees)
my_motor.run_angle(500, 1080)  # Speed: 500 deg/s, Angle: 1080 degrees

# Wait for the motor to finish
while not my_motor.done():
    wait(10)
Think of motor speed like a bicycle: The bigger the number, the faster you pedal. Positive numbers = forward, negative numbers = backward!

🔬 Motor Math!

If a wheel does one full spin (360°), how many degrees for 5 spins?

Click to see the answer!

5 × 360 = 1800 degrees! Use motor.run_angle(500, 1800) to spin exactly 5 times!

🎯 Motor Challenges!

🎯 Motor Mastery Check!

Can you:

✅ Make a motor spin forward?

✅ Control the speed?

✅ Spin an exact number of degrees?

✅ Stop the motor?

👁️ Sensors - Giving Robots Senses!

Sensors = Robot Senses!

Just like you have eyes to see and ears to hear, robots have sensors to understand the world around them!

👁️
Color Sensor
Like eyes for colors
📏
Distance Sensor
Like a ruler for space
👆
Force Sensor
Like touch feeling

Each sensor gives your robot a different superpower!

👁️ Color Sensor Magic
from pybricks.pupdevices import ColorSensor
from pybricks.parameters import Color

# Connect color sensor to Port C
color_sensor = ColorSensor(Port.C)

# Check what color it sees
detected_color = color_sensor.color()

if detected_color == Color.RED:
    print("I see a red apple! 🍎")
    hub.light.on(Color.RED)
elif detected_color == Color.GREEN:
    print("I see green grass! 🌱")
    hub.light.on(Color.GREEN)
elif detected_color == Color.BLUE:
    print("I see the blue sky! ☁️")
    hub.light.on(Color.BLUE)
else:
    print("Hmm, interesting color!")

# Check reflection (0 = dark, 100 = bright)
# This measures reflected light from the sensor's own light
reflection = color_sensor.reflection()
if reflection < 30:
    print("Dark surface detected! 🌙")
else:
    print("Light surface detected! ☀️")
📏 Distance Sensor
from pybricks.pupdevices import UltrasonicSensor

# Connect distance sensor to Port D
distance_sensor = UltrasonicSensor(Port.D)

# Measure distance in millimeters
distance = distance_sensor.distance()

# Convert to centimeters for easier understanding
if distance is not None:  # Check if reading is valid
    distance_cm = distance / 10
    print(f"Object is {distance_cm} cm away!")
else:
    print("No object detected!")

if distance_cm < 5:
    print("SUPER CLOSE! 🛑")
    hub.speaker.beep(1000, 500)  # High beep
elif distance_cm < 20:
    print("Getting closer! ⚠️")
    hub.speaker.beep(500, 500)  # Medium beep
else:
    print("Lots of room! ✅")
    hub.speaker.beep(200, 500)  # Low beep
The distance sensor is like playing "Hot and Cold"! It tells you how close you are to something. The closer you get, the smaller the number!

🔬 Sensor Science!

If the color sensor sees a black line on white paper, which has higher reflection?

Click to see the answer!

White paper has higher reflection (maybe 70-90)! Black absorbs light, so it has low reflection (maybe 10-20).

🎯 Sensor Challenges!

🤖 Build Your First Moving Robot!

Time to Build a Real Robot!

Let's combine everything you've learned to make a robot that can move around and avoid obstacles!

🤖 Your Robot Setup
⚙️ Left Motor (Port A)
🤖
⚙️ Right Motor (Port B)
📏 Distance Sensor (Port D)

Two motors for movement, one sensor for seeing!

🤖 Simple Drive Base
from pybricks.robotics import DriveBase
from pybricks.pupdevices import Motor
from pybricks.parameters import Port, Direction

# Set up your robot's motors
left_motor = Motor(Port.A, Direction.COUNTERCLOCKWISE)
right_motor = Motor(Port.B)

# Create a DriveBase - this makes driving easy!
# wheel_diameter: How big your wheels are (in mm)
# axle_track: Distance between wheels (in mm)
robot = DriveBase(
    left_motor, 
    right_motor, 
    wheel_diameter=56,  # Standard LEGO wheel
    axle_track=112      # Measure your robot!
)

# Now driving is super easy!
robot.straight(200)    # Drive forward 200mm
robot.turn(90)         # Turn right 90 degrees
robot.straight(200)    # Drive forward again
robot.turn(90)         # Turn right again

print("I just drove in an L shape!")
🚗 Obstacle Avoiding Robot!
# Complete obstacle avoiding robot
from pybricks.hubs import PrimeHub
from pybricks.pupdevices import Motor, UltrasonicSensor
from pybricks.parameters import Port, Direction, Color, Button
from pybricks.robotics import DriveBase
from pybricks.tools import wait

# Initialize everything
hub = PrimeHub()
left_motor = Motor(Port.A, Direction.COUNTERCLOCKWISE)
right_motor = Motor(Port.B)
eyes = UltrasonicSensor(Port.D)  # The robot's "eyes"

# Create the robot
robot = DriveBase(left_motor, right_motor, 56, 112)

print("Press center button to start!")
print("I'll avoid obstacles automatically!")

# Wait for button press to start
while Button.CENTER not in hub.buttons.pressed():
    wait(10)

# Main robot brain loop
while True:
    # Check if we should stop
    if Button.CENTER in hub.buttons.pressed():
        print("Stopping robot!")
        break
    
    # Look ahead
    distance = eyes.distance()
    
    # Check if reading is valid
    if distance is not None and distance < 200:  # Something is close (200mm = 20cm)
        # Oh no! Obstacle detected!
        hub.light.on(Color.RED)
        robot.stop()
        
        # Back up a bit
        robot.straight(-100)
        
        # Look for a clear path
        robot.turn(45)  # Try turning right
        wait(500)
        
        if eyes.distance() < 200:  # Still blocked?
            robot.turn(-90)  # Try left instead
    else:
        # Path is clear - full speed ahead!
        hub.light.on(Color.GREEN)
        robot.drive(150, 0)  # Drive at 150 mm/s
    
    wait(100)  # Small pause to not overwhelm the robot

robot.stop()
hub.light.off()
print("Adventure complete!")

🔬 Robot Behavior!

What happens if you change the obstacle distance from 200 to 500?

Click to see the answer!

The robot will be more careful! It will stop and turn when objects are farther away (50cm instead of 20cm).

🎯 Robot Challenges!

🏆 Amazing Work!

You've built and programmed a real robot! You're ready for any robotics challenge!

⚡ Async/Await - Parallel Robot Powers!

What is Async/Await?

Imagine you're juggling - you don't wait for one ball to come down before throwing the next! Async/await lets your robot do multiple things at once, like moving forward WHILE scanning for obstacles!

Normal vs Async
❌ Normal (Sequential)
1️⃣ Move forward
2️⃣ THEN scan
3️⃣ THEN turn
⏱️ Total: 6 seconds
✅ Async (Parallel)
🔄 Move forward
+ Scan WHILE moving
+ Update display
⏱️ Total: 2 seconds!

Async makes your robot faster and smarter!

⚡ Basic Async Example
from pybricks.tools import multitask, run_task

# Define async functions with 'async def'
async def blink_lights():
    """Blink lights continuously"""
    for i in range(10):
        hub.light.on(Color.RED)
        await wait(250)  # 'await' = can do other things
        hub.light.on(Color.GREEN)
        await wait(250)

async def drive_forward():
    """Drive forward for 3 seconds"""
    robot.drive(200, 0)
    await wait(3000)
    robot.stop()

async def make_sounds():
    """Beep every second"""
    for i in range(3):
        hub.speaker.beep()
        await wait(1000)

# Run all three at the same time!
async def main():
    print("Starting multi-tasking robot!")
    await multitask(
        blink_lights(),
        drive_forward(),
        make_sounds()
    )
    print("All tasks complete!")

# Start the async program
run_task(main())
Think of async like a chef cooking: You don't wait for water to boil before chopping vegetables. You start the water heating, THEN chop while it heats. That's multitasking!
🤖 Real FLL Example - Attachment Control
from pybricks.tools import multitask, run_task

# Motors for different parts
drive_base = DriveBase(left_motor, right_motor, 56, 112)
arm_motor = Motor(Port.C)
claw_motor = Motor(Port.D)

async def drive_to_mission():
    """Drive to the mission model"""
    await drive_base.straight(500)  # 500mm forward
    await drive_base.turn(90)       # Turn right
    await drive_base.straight(300)  # 300mm forward

async def prepare_arm():
    """Get arm ready while driving"""
    await arm_motor.run_target(500, 90)  # Lift arm to 90 degrees
    
async def open_claw():
    """Open claw to grab object"""
    await claw_motor.run_angle(200, -45)  # Open claw

# Main mission - do multiple things at once!
async def complete_mission():
    # Drive and prepare arm AT THE SAME TIME
    await multitask(
        drive_to_mission(),
        prepare_arm()
    )
    
    # Now grab the object
    await open_claw()
    await claw_motor.run_angle(200, 45)  # Close claw
    
    # Drive back with object
    await drive_base.straight(-800)
    
    print("Mission complete in record time!")

# Run the mission
run_task(complete_mission())

🔬 Async Speed Test!

If driving takes 3 seconds and lifting arm takes 2 seconds, how long does it take with multitask?

Click to see the answer!

Only 3 seconds! Both happen at the same time, so it takes as long as the longest task (driving). You saved 2 seconds!

🏁 Racing Tasks - First One Wins!
# Sometimes you want to stop when ANY condition is met
from pybricks.tools import multitask, run_task

async def wait_for_touch():
    """Wait for force sensor to be pressed"""
    force = ForceSensor(Port.E)
    while not force.pressed():
        await wait(50)
    return "Touch detected!"

async def wait_for_color():
    """Wait for red color"""
    color = ColorSensor(Port.F)
    while color.color() != Color.RED:
        await wait(50)
    return "Red detected!"

async def wait_for_timeout():
    """Maximum 10 second timeout"""
    await wait(10000)
    return "Time's up!"

async def main():
    print("Waiting for: touch, red color, or 10 seconds...")
    
    # race=True means stop when FIRST task finishes
    winner = await multitask(
        wait_for_touch(),
        wait_for_color(),
        wait_for_timeout(),
        race=True
    )
    
    # See which one finished first
    print(f"Winner: {winner}")
    hub.speaker.beep()

run_task(main())

🎯 Async Challenges!

⚡ Async Mastery Check!

Can you:

✅ Use async def to define parallel functions?

✅ Use await with motor commands?

✅ Run multiple tasks with multitask()?

✅ Use race=True for first-wins scenarios?

🎮 DriveBase Pro Features

DriveBase Settings & Tuning

Your DriveBase is like a race car - you can tune it for speed, accuracy, or smoothness! Let's unlock its full potential!

🏎️ Speed & Acceleration Settings
from pybricks.robotics import DriveBase

# Create your drive base
robot = DriveBase(left_motor, right_motor, 56, 112)

# Get current settings
print("Default settings:", robot.settings())

# Customize for SPEED!
robot.settings(
    straight_speed=500,     # Max speed for straight (mm/s)
    straight_acceleration=1000,  # How fast to reach max speed
    turn_rate=200,         # Max turn speed (deg/s)
    turn_acceleration=500   # How fast to reach max turn speed
)

# Customize for PRECISION (FLL missions!)
robot.settings(
    straight_speed=200,     # Slower = more accurate
    straight_acceleration=100,   # Gentle acceleration
    turn_rate=90,          # Careful turns
    turn_acceleration=200
)

# Different speeds for different missions
def speed_mode(mode):
    if mode == "FAST":
        robot.settings(500, 1000, 200, 500)
        hub.light.on(Color.RED)
    elif mode == "PRECISE":
        robot.settings(150, 100, 60, 150)
        hub.light.on(Color.GREEN)
    elif mode == "NORMAL":
        robot.settings(300, 500, 120, 300)
        hub.light.on(Color.BLUE)
🎯 Use Gyro for Accurate Turns
# The hub has a built-in gyro (IMU)!
from pybricks.robotics import DriveBase

# Create drive base with use_gyro=True for better accuracy
robot = DriveBase(
    left_motor, 
    right_motor, 
    wheel_diameter=56,
    axle_track=112,
    use_gyro=True  # Uses hub's gyro for straight driving!
)

# Reset the gyro angle
robot.reset()

# Super accurate driving - gyro keeps it straight!
robot.straight(1000)  # Will stay perfectly straight

# Check how far you've driven
distance_traveled = robot.distance()
angle_turned = robot.angle()
print(f"Traveled: {distance_traveled}mm")
print(f"Turned: {angle_turned} degrees")

# Drive until you've gone exactly 1 meter
while robot.distance() < 1000:
    robot.drive(200, 0)
robot.stop()
🔄 Curve Driving
# Drive in curves and arcs!
from pybricks.tools import wait

# Drive in a circle (speed, turn_rate)
robot.drive(200, 50)  # Forward while turning
wait(4000)  # Complete a circle
robot.stop()

# Drive in figure-8 pattern
async def figure_eight():
    # First circle
    robot.drive(200, 45)
    await wait(4000)
    
    # Second circle (opposite direction)
    robot.drive(200, -45)
    await wait(4000)
    
    robot.stop()

# Arc to a specific point
def arc_turn(radius, angle):
    """Drive in an arc with specific radius"""
    # Calculate turn rate based on radius
    speed = 200
    turn_rate = speed / radius
    
    # Calculate time needed
    arc_length = radius * angle * 3.14159 / 180
    time_ms = int(arc_length / speed * 1000)
    
    robot.drive(speed, turn_rate)
    wait(time_ms)
    robot.stop()

# Example: 500mm radius, 90 degree arc
arc_turn(500, 90)

🔬 DriveBase Physics!

If you double the acceleration setting, what happens to your robot?

Click to see the answer!

It reaches top speed twice as fast! But be careful - too much acceleration can make wheels slip or the robot tip!

📊 Data Logging & Debugging

Become a Robot Detective!

When your robot isn't working right, data logging helps you see what's really happening. It's like a flight recorder for your robot!

📝 Basic Data Logging
from pybricks.tools import DataLog, StopWatch

# Create a data log with column names
data = DataLog("time", "distance", "reflection", "speed")

# Create a timer
timer = StopWatch()

# Collect data while driving
color_sensor = ColorSensor(Port.C)

for i in range(100):  # Collect 100 samples
    # Log current values
    data.log(
        timer.time(),
        robot.distance(),
        color_sensor.reflection(),
        left_motor.speed()
    )
    
    # Drive forward
    robot.drive(200, 0)
    wait(100)  # Log every 100ms

robot.stop()

# Data is automatically saved!
print("Data logged! Check the Pybricks app to download.")
🐛 Debug Helper Functions
# Useful debugging helpers
def debug_print(message, value=None):
    """Print with timestamp"""
    time = timer.time() / 1000.0
    if value is not None:
        print(f"[{time:.2f}s] {message}: {value}")
    else:
        print(f"[{time:.2f}s] {message}")

def check_sensors():
    """Print all sensor values"""
    print("=== SENSOR CHECK ===")
    print(f"Color: {color_sensor.color()}")
    print(f"Reflection: {color_sensor.reflection()}")
    print(f"Distance: {distance_sensor.distance()}")
    print(f"Left motor angle: {left_motor.angle()}")
    print(f"Right motor angle: {right_motor.angle()}")
    print("==================")

def beep_error(error_code):
    """Different beep patterns for different errors"""
    if error_code == 1:  # Sensor error
        hub.speaker.beep(1000, 100)
        wait(100)
        hub.speaker.beep(1000, 100)
    elif error_code == 2:  # Motor stall
        hub.speaker.beep(500, 500)
    elif error_code == 3:  # Mission fail
        hub.speaker.beep(200, 1000)

# Use in your code
debug_print("Starting mission")
check_sensors()

if color_sensor.reflection() < 10:
    debug_print("ERROR: Too dark", color_sensor.reflection())
    beep_error(1)

🔬 Debug Detective!

Your robot turns left instead of right. What's the first thing to check?

Click to see the answer!

Check if motors are in correct ports and direction! Use debug_print to show motor.angle() values when turning. Maybe Port.A and Port.B are swapped!

💡 Fun Projects to Try

Project 1: Dancing Robot

Make your robot dance to a beat!

🕺 Robot Dance Party
from pybricks.hubs import PrimeHub
from pybricks.pupdevices import Motor
from pybricks.parameters import Port, Direction, Color, Icon
from pybricks.robotics import DriveBase
from pybricks.tools import wait

hub = PrimeHub()
left_motor = Motor(Port.A, Direction.COUNTERCLOCKWISE)
right_motor = Motor(Port.B)
robot = DriveBase(left_motor, right_motor, wheel_diameter=56, axle_track=112)

# Dance moves
def spin():
    robot.turn(360)

def wiggle():
    for i in range(3):
        robot.turn(30)
        robot.turn(-30)

def forward_back():
    robot.straight(100)
    robot.straight(-100)

# Dance routine
dance_moves = [spin, wiggle, forward_back, wiggle, spin]

for move in dance_moves:
    hub.light.on(Color.BLUE)
    move()
    hub.light.on(Color.RED)
    wait(500)

# Take a bow
hub.display.icon(Icon.HAPPY)
hub.speaker.beep()

Project 2: Color Memory Game

Create a Simon Says style memory game!

🎮 Memory Challenge
from pybricks.hubs import PrimeHub
from pybricks.parameters import Color, Button
from pybricks.tools import wait
import random

hub = PrimeHub()

# Game settings
colors = [Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW]
sequence = []
player_input = []

def show_sequence():
    """Display the color sequence"""
    for color in sequence:
        hub.light.on(color)
        hub.speaker.beep(frequency=colors.index(color) * 200 + 400)
        wait(600)
        hub.light.off()
        wait(200)

def add_to_sequence():
    """Add random color to sequence"""
    sequence.append(random.choice(colors))

# Main game
print("Watch the sequence and repeat it!")
for round in range(5):
    add_to_sequence()
    show_sequence()
    print(f"Round {round + 1}: Remember {len(sequence)} colors!")
    wait(2000)

print("Great memory skills!")

📚 Tips for Success

🎯 FLL Competition Tips

  • Test Everything: Run your programs multiple times from different starting positions
  • Use Constants: Define wheel size, axle track, and speeds at the top of your program
  • Battery Matters: Low battery = slower motors. Test with different battery levels
  • Modular Code: Write functions for each mission so you can test them separately
  • Document Everything: Comment your code so teammates understand it

🐛 Debugging Like a Pro

Debug Template
# Debug mode flag
DEBUG = True

def debug_print(message):
    if DEBUG:
        print(f"[DEBUG] {message}")

# Use throughout your code
debug_print("Starting mission")
debug_print(f"Sensor reading: {color_sensor.reflection()}")
debug_print(f"Motor angle: {motor.angle()}")

⚡ Performance Optimization

Speed vs Accuracy Trade-offs:

  • Fast for long distances between missions
  • Slow and precise when approaching mission models
  • Use async for parallel operations (saves precious seconds!)
  • Pre-position attachments while driving

📋 Competition Day Checklist

Before Each Run:

✅ Fresh battery installed

✅ Robot in correct starting position

✅ Attachments secure

✅ Program selected

✅ Team knows their roles

✅ Deep breath, you've got this!

🎉 You're a Robot Programmer!

🌟 Look What You've Learned!

✅ How to write Python code

✅ Control lights and displays

✅ Use variables and loops

✅ Make decisions with if statements

✅ Control motors

✅ Read sensors

✅ Build complete robots!

What's Next?

🚀 Join your school's robotics club!

🏆 Compete in FIRST LEGO League!

💡 Create your own robot inventions!

📚 Keep learning and exploring!

Remember: Every expert was once a beginner.

Keep coding, keep building, keep learning!

🤖❤️👨‍💻