Create potentiometer-neopixels.py

first submission for Make It Twist - Potentiometers
This commit is contained in:
Mike Barela 2018-09-11 14:31:39 -04:00 committed by GitHub
parent 67fbca1ebe
commit 3fba62a5a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,22 @@
import time
import board
from analogio import AnalogIn
import neopixel
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, auto_write=False) # CPX NeoPixels
potentiometer = AnalogIn(board.A1) # potentiometer connected to A1, power & ground
def show_value(val): # Show value 0-9 on CPX NeoPixels
for i in range(val):
pixels[i] = (10*(i+1), 0, 0)
for i in range(val, 10):
pixels[i] = (0, 0, 0)
pixels.show()
return
while True:
show_value(int(potentiometer.value / 6500)) # Show on NeoPixels
print((potentiometer.value,)) # Print value
time.sleep(0.25) # Wait a bit before checking all again