from machine import Pin, ADC
import utime
"""
65536 100
potreading xp
xp=potreading * 100/65536
"""
# VARIABLES PARA EL LDR
factor = 3.3 / (65535)
fporcentaje = 100/65536
umbral= 50
ldr_value = ADC(27)
# vALOR PARA LA LAECTURA DEL ADC
set_point_value = ADC(28)
# OBJETOS PARA MANEJO DE LEDS
led_externo = Pin(7, Pin.OUT)
Relay = Pin(10, Pin.OUT)
boton = Pin(18, Pin.IN, Pin.PULL_UP)
while True:
if boton.value() == 1:
led_externo.value(0)
else:
led_externo.value(1)
#Calculo de datos de intensidad de Luz
potreadingLDR = ldr_value.read_u16()
porcentajeLUZ = potreadingLDR*fporcentaje
#Calculo de datos de SetPoint
potreadingSetPoint = set_point_value.read_u16()
porcentajeSetPoint = potreadingSetPoint*fporcentaje
print("potADCLDR: ",potreadingLDR," PorcentajeLDR:", porcentajeLUZ,"SP: ",potreadingSetPoint," PorcentajeSP:", porcentajeSetPoint)
if porcentajeLUZ>porcentajeSetPoint:
print("Muy luminoso")
Relay.value(0)
else:
print("poco luminoso")
Relay.value(1)
utime.sleep(0.1)