from machine import Pin, ADC, Timer
from neopixel import NeoPixel
from time import sleep
# set all colours to zero initially
red = 0
green = 0
blue = 0
ring = NeoPixel(Pin(12), 16) # initialize 16-element NeoPixel Ring on GPIO pin 12
pot1 = ADC(Pin(36)) # pin 36 will be used as an ADC input line
pot2 = ADC(Pin(39)) # pin 39 will be used as an ADC input line
pot3 = ADC(Pin(34)) # pin 34 will be used as an ADC input line
switch = Pin(19,Pin.IN,Pin.PULL_UP)
def my_timer_ISR (timer): # internal interrupt service routine (ISR)
global red,green,blue
red = int(pot1.read()/16)
green = int(pot2.read()/16)
blue = int(pot3.read()/16)
my_timer = Timer(0)
my_timer.init(mode = Timer.PERIODIC, period = 100, callback = my_timer_ISR )
while True:
direction = switch.value() # inspect switch position
if direction == 0: # clockwise rotation
for i in range(16):
ring[i] = (red, green, blue)
ring.write()
sleep(0.25)
else: # anti-clockwise rotation
for i in range(15,-1,-1):
ring[i] = (red, green, blue)
ring.write()
sleep(0.25)