Every inventor began with one small project. Pick one and bring your idea to life today!
Great inventors and great teachers all started with one small step. Take yours today!
The same kits we use in 40+ school labs — grab yours and build something you’re proud of.
Log in to continue
Smart gadgets decide (“if the button is pressed, ring the bell”) and repeat (“beep 3 times”, “wait until someone presses start”). With if, repeat, for and while your board starts to think — and saves you from typing the same lines again and again!
if asks a yes / no question; its indented lines run only when the answer is yes. elif (“else if”) asks another question. else runs when every answer was no.
Runs the indented lines exactly n times, then the program moves on.
Runs the lines n times and counts in i: 0, 1, 2 … up to n − 1.
Repeats the indented lines as long as the condition is yes — like “wait while the start button is OFF”.
Jumps out of the repeat, for or while it is in, straight away.
Hold the button and watch the program choose its path: the if lines or the else lines.
Pick repeat(3) or for i in range(5), press Run and count every round.
# Add the libraries you need import buzzer # Give your pins easy-to-remember names i1 = set_name("button") o1 = set_name("bell") # ===== Doorbell ===== # This code block executes only once setup: button = set_input(push_button, active_low) bell = set_output(buzzer) # This code block executes forever loop: if button == ON: # when button is ON bell = ON # turn bell ON else: # otherwise bell = OFF # turn bell OFF
A doorbell with if and else: while the button on i1 is pressed the bell (a buzzer on o1) rings, otherwise it is quiet. Because this is inside loop, the board asks the question again and again.
# Give your pins easy-to-remember names i1 = set_name("player1") i2 = set_name("player2") o1 = set_name("light1") o2 = set_name("light2") # ===== Quiz buzzer ===== # This code block executes only once setup: player1 = set_input(push_button, active_low) player2 = set_input(push_button, active_low) light1 = set_output(led) light2 = set_output(led) # This code block executes forever loop: if player1 == ON: # when player1 is ON light1 = ON # turn light1 ON wait(3000) # keep the winner’s light on for 3 seconds light1 = OFF # turn light1 OFF elif player2 == ON: # otherwise, when player2 is ON light2 = ON # turn light2 ON wait(3000) # pause here for 3000 milliseconds before continuing light2 = OFF # turn light2 OFF
Quiz buzzer for two players with if and elif: whoever presses first lights their LED for 3 seconds. If both press at the same moment, only the first block (player 1) runs — the board checks from the top. No else is needed here.
# Add the libraries you need import buzzer # Give your pins easy-to-remember names i1 = set_name("button") o1 = set_name("beeper") # ===== Three-beep alarm ===== # This code block executes only once setup: button = set_input(push_button, active_low) beeper = set_output(buzzer) # This code block executes forever loop: if button == ON: # when button is ON repeat(3): # repeat the steps below 3 times in a row beeper = ON # turn beeper ON wait(200) # pause here for 200 milliseconds before continuing beeper = OFF # turn beeper OFF wait(200) # pause here for 200 milliseconds before continuing
Three-beep alarm: a repeat inside an if. One press of the button gives exactly three beeps (on 200 ms, off 200 ms each).
# Give your pins easy-to-remember names i1 = set_name("start") i2 = set_name("stop") o1 = set_name("lamp") # ===== Start and stop show ===== # This code block executes only once setup: start = set_input(push_button, active_low) stop = set_input(push_button, active_low) lamp = set_output(led) # This code block executes forever loop: # wait here until the start button is pressed while start == OFF: # keep repeating the steps below while start is OFF wait(20) # pause here for 20 milliseconds before continuing for i in range(10): # repeat the steps below 10 times, counting each time in i lamp = ON # turn lamp ON wait(300) # pause here for 300 milliseconds before continuing lamp = OFF # turn lamp OFF wait(300) # pause here for 300 milliseconds before continuing if stop == ON: # when stop is ON break # stop this loop now and go on after it
while and break together: the program waits in the while until start (i1) is pressed, then blinks the lamp up to 10 times with a for loop. Holding stop (i2) when a blink ends breaks out of the for loop early — the board checks stop once per round. Then loop starts again and waits for start.
If someone is near → open. Else → stay closed. Every automatic door at a mall or airport runs an if / else.
“Do 10 jumping jacks” is a repeat(10) for humans. “Run until the whistle blows” is a while!
Rocket launches count down 10, 9, 8 … 1 — a loop with a counter, ending with a big “liftoff!”.
Two buttons (i1, i2) and two LEDs (o1, o2), named player1, player2, light1 and light2. If player 1 presses, light 1 glows for 3 seconds; elif player 2 presses, light 2 glows. Add a buzzer on o3 that beeps once for every winner.
🧰 You need: 2 push buttons, 2 LEDs, a buzzer, TinkerPy board or SimulatorA button on i1 and a buzzer on o1. When the button is pressed, beep exactly 3 times with repeat(3). Then change it to a for loop that beeps 5 times, a little longer each time.
🧰 You need: push button, buzzer, TinkerPy board or SimulatorA self-driving car makes a huge number of if-style decisions every second: if a person is ahead, slow down; if the light is red, stop…
5 quick questions to check yourself — free with your TinkerPy account.
Log in