Adafruit_Learning_System_Gu.../MetroX_CircuitPython/photo_sensor/code.py
2022-02-22 13:45:02 -05:00

22 lines
460 B
Python
Executable file

# SPDX-FileCopyrightText: 2021 Brent Rubell for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
'photo_sensor.py'.
=================================================
uses LIGHT to control a LED
"""
import analogio
import board
import pwmio
from simpleio import map_range
LED = pwmio.PWMOut(board.D9)
LIGHT = analogio.AnalogIn(board.A0)
while True:
LIGHT_VAL = map_range(LIGHT.value, 20000, 32766, 0, 32766)
LED.duty_cycle = int(LIGHT_VAL)