import time
import neopixel
from machine import Pin, PWM
np = neopixel.NeoPixel(Pin(22, Pin.OUT), 16)
buzzer = PWM(Pin(23))
melody = [262, 294, 330, 349, 392, 440, 494, 523]
def crossfade(color1, color2, steps):
r_step = (color2[0] - color1[0]) / steps
g_step = (color2[1] - color1[1]) / steps
b_step = (color2[2] - color1[2]) / steps
for i in range(steps):
r = color1[0] + (r_step * i)
g = color1[1] + (g_step * i)
b = color1[2] + (b_step * i)
np.fill((int(r), int(g), int(b)))
np.write()
time.sleep(0.05)
def play_melody():
for note in melody:
buzzer.duty(50)
buzzer.freq(note)
time.sleep(0.3)
buzzer.duty(0)
time.sleep(0.1)
while True:
crossfade((255, 0, 0), (0, 255, 0), 50)
play_melody()
crossfade((0, 255, 0), (0, 0, 255), 50)
play_melody()
crossfade((0, 0, 255), (255, 0, 0), 50)
play_melody()