# SPDX-FileCopyrightText: 2020 FoamyGuy for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
This example script shows how to read button state with
debouncing that does not rely on time.sleep().
"""
import board
from digitalio import DigitalInOut, Direction, Pull
import neopixel
from rainbowio import colorwheel
import time
import digitalio
import analogio
import pwmio
potentiometer = analogio.AnalogIn(board.GP28)
switch_1 = DigitalInOut(board.GP13)
switch_1.direction = Direction.INPUT
switch_2 = DigitalInOut(board.GP14)
switch_2.direction = Direction.INPUT
num_pixels = 16
def get_voltage(pin):
return (int(pin.value * 3.3) / 65536)
pixels = neopixel.NeoPixel(pwmio.PWMOut(board.GP16, frequency=1000))
pixels.brightness = ((get_voltage(potentiometer),))
def rainbow(speed):
for j in range(255):
for i in range(num_pixels):
pixel_index = (i * 256 // num_pixels) + j
pixels[i] = colorwheel(pixel_index & 255)
pixels.show()
time.sleep(0.005)
turn_off = (0, 0, 0)
while True:
print((get_voltage(potentiometer),))
time.sleep(0.1)
if switch_2.value:
pixels.fill(turn_off)
pixels.show()
else:
rainbow(0)