Created
May 12, 2023 21:47
-
-
Save lizzybrooks/e49022a04b1c86e6ab916daccd633d6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import analogio | |
import board | |
import neopixel | |
import math | |
dial_pin = board.A2 #pin 0 is Analog input 2 | |
dial = analogio.AnalogIn(dial_pin) | |
pixel_pin = board.D2 | |
num_pixels = 16 | |
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.5, auto_write=False) | |
ONE = (252, 0, 184) | |
TWO = (189, 5, 245) | |
THREE = (113, 5, 255) | |
OFF = (0,0,0) | |
while True: | |
time.sleep(0.2) | |
#print((math.sqrt(dial.value,))) | |
val = int(math.sqrt(dial.value)-20) #scale down potentiometer values to fit within color range | |
print(val) | |
if(val<28): | |
pixels.fill(ONE) | |
pixels.show() | |
if(56>val>28): | |
pixels.fill(TWO) | |
pixels.show() | |
if(84>val>56): | |
pixels.fill(THREE) | |
pixels.show() | |
if(val>84): | |
pixels.fill(OFF) | |
pixels.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment