from machine import Pin
from neopixel import NeoPixel
from time import sleep
# Broche de commande + nombre de pixels
PIN = 15
NB_PIXELS = 16
# Palette de couleurs (valeurs hautes = plus lumineuses)
rainbow = [
(255, 0, 0), # Rouge
(255, 128, 0), # Orange
(255, 255, 0), # Jaune
(0, 255, 0), # Vert
(0, 255, 255), # Cyan
(0, 0, 255), # Bleu
(128, 0, 255), # Indigo
(255, 0, 255) # Magenta
]
# Initialisation des NeoPixels
pixels = NeoPixel(Pin(PIN), NB_PIXELS)
# Fonction pour afficher la palette décalée
def show_rainbow(shift):
for i in range(NB_PIXELS):
color = rainbow[(i + shift) % len(rainbow)]
pixels[i] = color
pixels.write()
# Animation
shift = 0
while True:
show_rainbow(shift)
shift = (shift + 1) % len(rainbow)
sleep(0.1)