Last active
January 15, 2022 15:29
-
-
Save jaylandro/a7b490492e7c06c501177136e6376e91 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# -------------------------------------------------------------------- # | |
# CircuitPython Analog In detection set RGB to random color example | |
# -------------------------------------------------------------------- # | |
import time, board, neopixel, random | |
from analogio import AnalogIn | |
analog_in = AnalogIn(board.A1) | |
led = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=1) | |
def get_voltage(pin): | |
return (pin.value * 3.3) / 65536 | |
while True: | |
read_analog_in = get_voltage(analog_in) | |
neo_color = [random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)] | |
print((read_analog_in)) | |
if read_analog_in < 1: | |
led.fill(neo_color) | |
print(neo_color) | |
else: | |
led.fill([0,0,0]) | |
time.sleep(0.5) | |
# --------------------------------------- # | |
# CircuitPython 7 slow color fade qtpy | |
# --------------------------------------- # | |
# import time, board, neopixel | |
# try: | |
# from rainbowio import colorwheel | |
# except: | |
# def colorwheel(pos): | |
# if pos < 0 or pos > 255: return (0, 0, 0) | |
# if pos < 85: return (255 - pos * 3, pos * 3, 0) | |
# if pos < 170: pos -= 85; return (0, 255 - pos * 3, pos * 3) | |
# pos -= 170; return (pos * 3, 0, 255 - pos * 3) | |
# led = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=1) | |
# while True: | |
# led.fill( colorwheel((time.monotonic()*50)%255) ) | |
# time.sleep(0.05) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment