Adafruit_Learning_System_Gu.../MetroX_CircuitPython/potentiometer/code.py
2022-02-22 13:42:47 -05:00

29 lines
619 B
Python
Executable file

# SPDX-FileCopyrightText: 2021 Brent Rubell for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
'potentiometer.py'.
=================================================
control a LED's brightness using a potentiometer
"""
import time
import digitalio
import analogio
import board
LED = digitalio.DigitalInOut(board.D13)
LED.switch_to_output()
POT = analogio.AnalogIn(board.A0)
SENSOR_VAL = 0
while True:
# potentiometer value/max potentiometer value
SENSOR_VAL = POT.value / 65536
print(SENSOR_VAL)
LED.value = True
time.sleep(SENSOR_VAL)
LED.value = False
time.sleep(SENSOR_VAL)