Files
board-mate/esp32-lora/main.py
2025-12-25 02:02:08 +01:00

27 lines
657 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import time
from machine import Pin, ADC, I2C
from screen import Screen
# ----- ADC (Grove Light Sensor) -----
light_adc = ADC(Pin(1))
light_adc.atten(ADC.ATTN_11DB) # 03.3V range
light_adc.width(ADC.WIDTH_12BIT) # 04095
screen = Screen()
def read_light(samples=8):
total = 0
for _ in range(samples):
total += light_adc.read()
time.sleep_ms(5)
return total // samples
while True:
raw = read_light()
percent = int((raw / 4095) * 100)
screen.display("Light Sensor", 15, 0)
screen.display("Raw: {}".format(raw), 15, 20)
screen.display("Level: {}%".format(percent), 15, 40)
time.sleep(0.5)