powered by TinkerSpace.in
Join free
TinkerPy Projects lessons
๐Ÿ”˜
Lesson 4 of 10 ยท Starter ยท 10 min

Press the button

Make decisions with if and else.

๐Ÿ”Œ Wiring

Connect a push button to input i1 and an LED to output o1.

if asks a question. When the answer is yes, the lines indented under it run. else runs when the answer is no.

TinkerPy
setup:

loop:
    if i1 == ON:
        o1 = pwm(100)
    else:
        o1 = 0
The LED is on only while the button is pressed.
๐Ÿ’ก Tip

Notice the 4 spaces before the lines inside if and else. That is how TinkerPy knows which lines belong together.

๐Ÿš€ Your turn

Add a second LED on o2 that is ON when the button is not pressed.