for _ in range(3): runs the indented lines 3 times. Here the LED blinks 3 times when the board starts, then o2 stays on.
from tinkerpy_mega import * def setup(): for _ in range(3): write_output(o1, pwm(100)) wait(300) write_output(o1, 0) wait(300) def loop(): write_output(o2, pwm(100))
Variables remember numbers
A variable is a box with a name that holds a number. Here speed grows by 10 each time.
from tinkerpy_mega import * def setup(): pass # your code goes here def loop(): speed = 0 for _ in range(10): speed = speed + 10 write_output(o1, pwm(speed)) wait(200)
๐ Your turn
Change it so speed grows by 20 and repeats only 5 times.