#Import Pin, neopiexl and time modules. from machine import Pin import neopixel import time button1 = Pin(16, Pin.IN, Pin.PULL_UP) button2 = Pin(27, Pin.IN, Pin.PULL_UP) count = 0 #Define the number of pin and LEDs connected to neopixel. pin = Pin(26, Pin.OUT) np = neopixel.NeoPixel(pin, 4) #brightness :0-255 brightness=100 colors=[[0,0,0], [brightness,0,0], #red [0,brightness,0], #green [0,0,brightness], #blue [brightness,brightness,brightness] #white ] #close def func_color(val): for j in range(0,4): np[j]=colors[val] np.write() time.sleep_ms(50) #Nest two for loops to make the module repeatedly display five states of red, green, blue, white and OFF. while True: btnVal1 = button1.value() # Reads the value of button 1 #print("button1 =",btnVal1) #Print it out in the shell if(btnVal1 == 0): time.sleep(0.01) while(btnVal1 == 0): btnVal1 = button1.value() if(btnVal1 == 1): count = count - 1 print(count) if(count <= 0): count = 0 btnVal2 = button2.value() if(btnVal2 == 0): time.sleep(0.01) while(btnVal2 == 0): btnVal2 = button2.value() if(btnVal2 == 1): count = count + 1 print(count) if(count >= 4): count = 4 if(count == 0): func_color(0) elif(count == 1): func_color(1) elif(count == 2): func_color(2) elif(count == 3): func_color(3) elif(count == 4): func_color(4)