# Imports
from machine import Pin
from neopixel import NeoPixel
import time, random

# LED details
GPIOnumber = 28
LEDcount = 15

# set up buttons
cBtn=Pin(16,Pin.IN,Pin.PULL_UP)
sBtn=Pin(17,Pin.IN,Pin.PULL_UP)

# Define the strand pin number and number of LEDs from variables
strand = NeoPixel(Pin(GPIOnumber), LEDcount)

global mycolour
mycolour=(78,0,45)
# Turn off all LEDs before program start
strand.fill((mycolour))
strand.write()
time.sleep(1)

def ledStrand():
    i=random.randint(0,LEDcount-1)
    strand[i]=(0,0,0)
    strand.write()
    time.sleep(0.09)
    strand[i]=(mycolour)
    strand.write()
    time.sleep(0.09)
    
def nColor():
    global mycolour
    mycolour=(random.randint(0,255),random.randint(0,255),random.randint(0,255))
    time.sleep(0.09)
    
def clearStrand():
    strand.fill((0,0,0))
    strand.write()

while True:
    ledStrand()
    if sBtn.value()==0:
        clearStrand()
        break
    if cBtn.value()==0:
        nColor()