from machine import Pin, PWM
import time, math
red = PWM(Pin(15)); red.freq(1000)
green = PWM(Pin(14)); green.freq(1000)
blue = PWM(Pin(13)); blue.freq(1000)
def set_rgb_pwm(r, g, b):
red.duty_u16(r); green.duty_u16(g); blue.duty_u16(b)
print("レインボーグラデーション開始")
t = 0.0
while True:
val_r = int((math.sin(t) + 1) * 32767.5)
val_g = int((math.sin(t+2.094) + 1) * 32767.5)
val_b = int((math.sin(t+4.189) + 1) * 32767.5)
set_rgb_pwm(val_r, val_g, val_b)
time.sleep(0.05)
t += 0.05