-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmove_simple_led.py
More file actions
42 lines (34 loc) · 1.08 KB
/
Copy pathmove_simple_led.py
File metadata and controls
42 lines (34 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# examples/basic/move_simple_led.py
#
# Demonstrates: fading an LED using move()
# API style: call move() on every loop iteration
# Async equivalent: examples/async/move_simple_led.py
# Easing reference: https://philvanallen.com/easings_cheatsheet/
#
# GammaEaseIn/Out matches human eye sensitivity to brightness — use it for LEDs.
import board
import pwmio
from varspeed import Vspeed
MIN = 0
MAX = 65535
vs = Vspeed(init_position=MIN, result="int", debug=False)
vs.set_bounds(lower_bound=MIN, upper_bound=MAX)
led = pwmio.PWMOut(board.D2, frequency=5000, duty_cycle=0)
led.duty_cycle = MIN
print("fading UP...")
running = True
while running:
position, running, changed = vs.move(
new_position=MAX, time_secs=5, steps=100, easing="GammaEaseIn"
)
if changed:
led.duty_cycle = position
print("fading DOWN...")
running = True
while running:
position, running, changed = vs.move(
new_position=MIN, time_secs=5, steps=100, easing="GammaEaseOut", delay_start=3.0
)
if changed:
led.duty_cycle = position
print("done, now at " + str(vs.position))