Code: Select all
from machine import Pin, PWM
import utime
# R:D5 G:D6 B:D7
r = PWM(Pin(14, Pin.OUT), freq=500, duty=0)
# this line would make PWM work in a strange way
g = PWM(Pin(12, Pin.OUT), freq=500, duty=0)
b = PWM(Pin(13, Pin.OUT), freq=500, duty=0)
r.duty(0)
g.duty(0)
b.duty(0)
while True:
for i in range(512):
b.duty(i)
r.duty(i)
utime.sleep_ms(1)
for i in reversed(range(512)):
b.duty(i)
r.duty(i)
utime.sleep_ms(1)
If I comment the line for creating g object and g.duty(0), it works perfectly.
Can any one tell me why?Thanks.