# NeoPixels Rainbow on MicroPython
# Wokwi Example https://wokwi.com/arduino/projects/305569065545499202
from machine import Pin
from neopixel import NeoPixel
from time import sleep
import machine
def callback(p):
print('pin change', p)
#servo.set_angle(90)
#machine.enable_irq()
rainbow = [
(126 , 1 , 0),(114 , 13 , 0),(102 , 25 , 0),(90 , 37 , 0),(78 , 49 , 0),(66 , 61 , 0),(54 , 73 , 0),(42 , 85 , 0),
(30 , 97 , 0),(18 , 109 , 0),(6 , 121 , 0),(0 , 122 , 5),(0 , 110 , 17),(0 , 98 , 29),(0 , 86 , 41),(0 , 74 , 53),
(0 , 62 , 65),(0 , 50 , 77),(0 , 38 , 89),(0 , 26 , 101),(0 , 14 , 113),(0 , 2 , 125),(9 , 0 , 118),(21 , 0 , 106),
(33 , 0 , 94),(45 , 0 , 82),(57 , 0 , 70),(69 , 0 , 58),(81 , 0 , 46),(93 , 0 , 34),(105 , 0 , 22),(117 , 0 , 10)]
off = (0,0,0)
number_leds = 32
pixels = NeoPixel(Pin(15), number_leds)
button = Pin(2,Pin.IN,Pin.PULL_UP)
# button.irq(trigger=Pin.IRQ_RISING, handler=callback)
while True:
if not button.value() == False:
for i in range(number_leds):
pixels[i] = rainbow[i]
pixels[i - 1] = rainbow[i]
pixels.write()
sleep(0.05)
pixels[i] = off
pixels[i - 1] = off
pixels.write()
sleep(0.001)