Powered by TinkerSpace
Join free
TinkerPy Projects lessons
๐ŸŒ—
Lesson 3 of 10 ยท Starter ยท 10 min

Bright and dim

Use numbers from 0 to 100 to set brightness, and make a smooth fade.

pwm() can be any number from 0 to 100. pwm(100) is full power, pwm(50) is half, pwm(10) is a tiny glow.

TinkerPy
from tinkerpy_mega import *

def setup():
    pass  # your code goes here

def loop():
    write_output(o1, pwm(100))
    wait(1000)
    write_output(o1, pwm(50))
    wait(1000)
    write_output(o1, pwm(10))
    wait(1000)
Bright, medium, dim.

A smooth fade

output_increment_till(o1, 0, 100, 5, 50) climbs from 0 to 100 in steps of 5, waiting 50 ms between steps. output_decrement_till goes back down.

TinkerPy
from tinkerpy_mega import *

def setup():
    pass  # your code goes here

def loop():
    output_increment_till(o1, 0, 100, 5, 50)
    output_decrement_till(o1, 100, 0, 5, 50)
A โ€œbreathingโ€ light.
๐Ÿš€ Your turn

Make the fade slower by changing the last number from 50 to 100.

Chat with TinkerPy ๐Ÿ‘‹