from microbit import *
import neopixel

colours = [(255, 0  , 0  ),
           (255, 50, 0  ),
           (255, 255, 0  ),
           (50, 255, 0  ),
           (0  , 255, 0  ),
           (0  , 255, 50),
           (0  , 255, 255),
           (0  , 50, 255),
           (0  , 0  , 255),
           (50, 0  , 255),
           (255, 0  , 255),
           (255, 0  , 125),
           (0  , 0  , 0  )]

np = neopixel.NeoPixel(pin0, 1)

colour = 0
rainbow = False

while True:
    if pin1.read_analog() <= 960:
        np[0] = colours[colour]
        np.show()
        if button_a.is_pressed():
            colour += 1
            colour = colour % len(colours)
            rainbow = False
            np[0] = colours[colour]
            np.show()
            sleep(500)
        elif button_b.is_pressed():
            rainbow = True
            sleep(10)
        if rainbow:
            np[0] = colours[colour]
            np.show()
            colour += 1
            colour = colour % (len(colours) - 1)
            sleep(500)
    else:
         np[0] = (0, 0, 0)
         np.show()