Powered by TinkerSpace
Join free
TinkerPy Projects lessons
🔁
Lesson 6 of 10 · Explorer · 12 min

Repeat and variables

Do things many times, and remember numbers in variables.

repeat(3): runs the indented lines 3 times. Here the LED blinks 3 times when the board starts, then o2 stays on.

TinkerPy
setup:
    repeat(3):
        o1 = pwm(100)
        wait(300)
        o1 = 0
        wait(300)

loop:
    o2 = pwm(100)
A “hello” blink at start-up.

Variables remember numbers

A variable is a box with a name that holds a number. Here speed grows by 10 each time.

TinkerPy
setup:

loop:
    speed = 0
    repeat(10):
        speed = speed + 10
        o1 = pwm(speed)
        wait(200)
The LED gets brighter step by step.
🚀 Your turn

Change it so speed grows by 20 and repeats only 5 times.