-
Notifications
You must be signed in to change notification settings - Fork 1
/
PWM-2ch.py
48 lines (40 loc) · 931 Bytes
/
PWM-2ch.py
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
48
# test Pi Pico W PWM function
# J.Beale 22-Nov-2022
from machine import Pin, PWM
from time import sleep
dtime = 0.004 # PWM update delay time in seconds
step = 25 # PWM 16-bit increment per cycle
p1 = PWM(Pin(12))
p2 = PWM(Pin(13))
p1.freq(1000)
p2.freq(1000)
p1.duty_u16(0)
p2.duty_u16(0)
led = machine.Pin('LED', machine.Pin.OUT)
for i in range(4):
led.on()
sleep(0.25)
led.off()
sleep(0.25)
while True:
p1.duty_u16(0)
p2.duty_u16(0)
led.off()
for duty in range(0,65535,step):
p1.duty_u16(duty)
sleep(dtime)
led.on()
for i in range(0,65535,step):
duty = 65535-i
p1.duty_u16(duty)
sleep(dtime)
led.off()
p1.duty_u16(0)
for duty in range(0,65535,step):
p2.duty_u16(duty)
sleep(dtime)
led.on()
for i in range(0,65535,step):
duty = 65535-i
p2.duty_u16(duty)
sleep(dtime)