Powered by TinkerSpace
Join free
TinkerPy Projects lessons
๐Ÿท๏ธ
Lesson 5 of 10 ยท Explorer ยท 8 min

Give pins a name

Call o1 โ€œledโ€ and i1 โ€œbuttonโ€ so your code reads like English.

Names make code easier to read. At the top of the program, write button = i1 to give a pin a nickname.

TinkerPy
from tinkerpy_mega import *

button = i1
led = o1

def setup():
    pass  # your code goes here

def loop():
    if read_digital(button) == ON:
        write_output(led, pwm(100))
    else:
        write_output(led, 0)
Same program as before โ€” but much easier to understand!
๐Ÿ’ก Tip

In the Project editor, tap the PIN button: add or rename pin names, and Use names everywhere swaps o1/i1 for your names at once.

๐Ÿš€ Your turn

Name o2 buzzer and make it sound while the button is pressed.

Chat with TinkerPy ๐Ÿ‘‹