#Color Func
#Button Inputs to toggle LEDs and Neopixel Rings + Debouncing
#NeoPixel Rings Added + Rainbow
#Copyright (c) 2022 Paul Martino
import board, digitalio, time, neopixel
from adafruit_debouncer import Debouncer
#from rainbowio import colorwheel
# ----- Button Setup ----- #
button_a_input = digitalio.DigitalInOut(board.GP2)
button_a_input.direction = digitalio.Direction.INPUT
button_a_input.pull = digitalio.Pull.UP
button_a = Debouncer(button_a_input)
# ----- Color Setup ----- #
AMBER = (255, 100, 0)
AQUA = (50, 255, 255)
BLUE = (0, 0, 255)
CYAN = (0, 255, 255)
GOLD = (255, 222, 30)
GREEN = (0, 255, 0)
JADE = (0, 255, 40)
MAGENTA = (255, 0, 20)
OLD_LACE = (253, 245, 230)
ORANGE = (255, 40, 0)
PINK = (242, 90, 255)
PURPLE = (180, 0, 255)
RED = (255, 0, 0)
TEAL = (0, 255, 120)
YELLOW = (255, 150, 0)
WHITE = (255, 255, 255)
BLACK = (0, 0, 0) #OFF
# ----- LED/NeoPixel Setup ----- #
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
led_a = digitalio.DigitalInOut(board.GP3)
led_a.direction = digitalio.Direction.OUTPUT
pixels_microwave = neopixel.NeoPixel(board.GP21, 16, brightness=0.99, auto_write=False)
#pixels_microwave.fill(BLACK)
# ----- Functions ----- #
def func_colorwheel(pos):
# Input a value 0 to 255 to get a color value.
# The colours are a transition r - g - b - back to r.
if pos < 0 or pos > 255:
return (0, 0, 0, 0)
if pos < 85:
return (255 - pos * 3, pos * 3, 0, 0)
if pos < 170:
pos -= 85
return (0, 255 - pos * 3, pos * 3, 0)
pos -= 170
return (pos * 3, 0, 255 - pos * 3, 0)
def rainbow_cycle(rainbow_target, rainbow_speed):
for q in range(255):
for p in range(len(rainbow_target)):
rc_index = (p * 256 // len(rainbow_target)) + q
rainbow_target[p] = func_colorwheel(rc_index & 255)
rainbow_target.show()
time.sleep(rainbow_speed)
cw_index = 0
pixels_microwave.fill(BLACK)
pixels_microwave.show()
# ----- Program Loop ----- #
while True:
button_a.update()
if button_a.fell: #if button_a pressed
print("Button A Pressed - Oven Heat")
led_a.value = True
led.value = True
#pixels_microwave.fill(RED)
rainbow_cycle(pixels_microwave, .01) #(target, cycle speed; increase the number to slow down the rainbow)
#pixels_microwave.show()
# cw_index = (cw_index + 1) % 256 # run from 0 to 255
# pixels_microwave.fill(colorwheel(cw_index))
if button_a.rose: #if button_a rose
print("Button A Rose")
led_a.value = False
led.value = False
print("Done")
pixels_microwave.fill(BLACK)
pixels_microwave.show()