-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpwm.py
More file actions
47 lines (37 loc) · 1.12 KB
/
pwm.py
File metadata and controls
47 lines (37 loc) · 1.12 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
43
44
45
46
47
from machine import Pin, PWM
from time import sleep
import network
sta_if = network.WLAN(network.STA_IF)
sta_if.active(False)
ap_if = network.WLAN(network.AP_IF)
ap_if.active(False)
print("Killed networking")
pwm = [PWM(Pin(5), freq=500, duty=512),
PWM(Pin(4), freq=500, duty=512),
PWM(Pin(0), freq=500, duty=512),
PWM(Pin(14), freq=500, duty=512)]
max_width = 300
min_width = .1
mstep = 1.2
astep = [1, 3, 5, 7]
mode = "add"
cur_width = [min_width] * 4
if mode == "mult":
while True:
pwm.duty(int(cur_width))
sleep(0.01)
cur_width *= wstep
print("cur_width:", cur_width)
if cur_width > max_width or cur_width < min_width:
mstep = 1/mstep
cur_width *= mstep
else:
while True:
for i in range(len(pwm)):
# print("Set %d to %d"%(i, cur_width[i]))
pwm[i].duty(int(cur_width[i]))
cur_width[i] += astep[i]
if cur_width[i] > max_width or cur_width[i] < min_width:
astep[i] = -1 * astep[i]
cur_width[i] += astep[i]
sleep(0.01)