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
ON and OFF are just the start. TinkerPy has a whole Output Function toolbox: make one light the opposite of another, step a fan up and down with buttons, and fade a lamp smoothly โ each in a single line of code.
Sets an outputโs power from 0 to 100: fan = pwm(60). Numbers outside 0โ100 are clamped.
The opposite ON / OFF of a digital pin: green = invert(red). Works on digital pins only โ not pwm, servo or buzzer.
Raises an output once by a step, never above a limit: output_increment(fan, 35, 100, 100).
Jumps to a start value, then climbs step by step to an end value โ a smooth fade.
Flips an output between two values each time the line runs: first the ON value, then the OFF value.
Press Step and watch the brightness of lamp climb and fall, one step at a time.
Drag the slider: the ON-time of the wave and the LED brightness change together.
# Give your pins easy-to-remember names i1 = set_name("train_button") o1 = set_name("red") o2 = set_name("green") # ===== Railway crossing lights ===== # This code block executes only once setup: train_button = set_input(push_button, active_low) red = set_output(led) green = set_output(led) # This code block executes forever loop: if train_button == ON: # when train_button is ON red = ON # a train is coming: red ON else: # otherwise red = OFF # turn red OFF green = invert(red) # green is always the opposite of red
Railway crossing lights. While the train button is pressed, red is ON; otherwise it is OFF. green = invert(red) is always the opposite, so exactly one light is on. (Why not just red = train_button? That copies the wire level, and a pressed active-low button reads LOW, so the light would do the opposite!) Reading the output red back needs board firmware 2.26.
# Give your pins easy-to-remember names i1 = set_name("faster") i2 = set_name("slower") o1 = set_name("fan") # ===== Three-speed fan ===== # This code block executes only once setup: faster = set_input(push_button, active_low) slower = set_input(push_button, active_low) fan = set_output(fan) fan = OFF # turn fan OFF # This code block executes forever loop: if faster == ON: # when faster is ON output_increment(fan, 35, 100, 100) # one step up, never above 100 wait(300) # pause here for 300 milliseconds before continuing elif slower == ON: # otherwise, when slower is ON output_decrement(fan, 35, 0, 100) # one step down, never below 0 wait(300) # pause here for 300 milliseconds before continuing
A fan with three speeds and two buttons. Each press of faster adds 35 (0 โ 35 โ 70 โ 100, never above 100); slower takes 35 away (never below 0). The wait(300) stops one long press from jumping several speeds.
# Give your pins easy-to-remember names i1 = set_name("dark") i2 = set_name("button") o1 = set_name("lamp") o2 = set_name("reading_lamp") # ===== Breathing night light ===== # This code block executes only once setup: dark = set_input(light_sensor, active_low) button = set_input(push_button, active_low) lamp = set_output(led) reading_lamp = set_output(led) # This code block executes forever loop: if button == ON: # when button is ON output_flip(reading_lamp, 0, 80) # each press: 80, then 0, then 80 โฆ wait(300) # pause here for 300 milliseconds before continuing if dark == ON: # when dark is ON output_increment_till(lamp, 0, 100, 5, 40) # ramp lamp from 0 up to 100, 5 at a time, 40ms between steps output_decrement_till(lamp, 100, 0, 5, 40) # ramp lamp down from 100 to 0, 5 at a time, 40ms between steps else: # otherwise lamp = pwm(0) # set lamp to 0
A breathing night light. When the light sensor (digital, ON = dark) says it is dark, lamp fades up and down; in daylight it stays off. Each press of button flips the reading_lamp between 80 and 0.
At a railway level crossing the red lights flash for the road while the train has the green โ one is always the opposite of the other, just like invert().
A fan regulator clicks through fixed speeds โ the same idea as output_increment() with a step and a limit.
Some laptops and phones have a light that slowly breathes while asleep โ a fade in and a fade out, again and again.
Use a digital light sensor on i1 and an LED on o1. When it is dark the LED fades in and out with output_increment_till and output_decrement_till; try step 2 and wait 30 for a slower, calmer breath.
๐งฐ You need: TinkerPy board, light sensor module, LEDTwo buttons step a small 5 V fan up and down with output_increment and output_decrement. Add an LED that is ON whenever the fan is OFF using lamp = invert(โฆ) on a digital pin.
๐งฐ You need: TinkerPy board, 2 push buttons, small fan motor with driver, LEDOne line, output_increment_till(lamp, 0, 100, 1, 10), makes 100 tiny brightness steps in about one second โ so smooth that your eyes see one gentle glow.
5 quick questions to check yourself โ free with your TinkerPy account.
Log in