#呼吸燈RGB
from machine import Pin,PWM
from time import sleep

r = PWM(Pin(15)) 
g = PWM(Pin(2)) 
b = PWM(Pin(4)) 

# 初始化PWM的頻率為60Hz 
r.freq(60) 
g.freq(60) 
b.freq(60) 

# 初始化週期為0
r.duty(0) 
g.duty(0) 
b.duty(0) 

while True: 
    for i in range(1024): #PWM以10bit(2^10=1024)來遞增調整
        r.duty(i) 
        g.duty(i) 
        b.duty(i) 
        sleep(0.001) 
        
    for i in range(1023, -1, -1): #PWM以10bit(2^10=1024)來遞減調整
        r.duty(i) 
        g.duty(i) 
        b.duty(i) 
        sleep(0.001)