import machine
from machine import Pin, ADC, SoftI2C, sleep
from lcd_api import LcdApi
from i2c_lcd import I2cLcd
import time 
import utime
I2C_ADDR = 0x27
totalRows = 2
totalColumns = 16

sensor = ADC (Pin(34))
sensor.atten(ADC.ATTN_11DB)
sensor.width(ADC.WIDTH_12BIT)
ledRojo = Pin(19, Pin.OUT)
ledAmarrillo = Pin(18,Pin.OUT)
ledAzul = Pin(5,Pin.OUT)
ledVerde = Pin(4,Pin.OUT)

i2c = SoftI2C (scl=Pin(22),sda=Pin(21),freq= 10000)
lcd = I2cLcd (i2c,I2C_ADDR,totalRows,totalColumns)

while True:
    lcd.putstr("amarillo si es mayor a 25kg")
    time.sleep(2)
    lcd.clear()
    lcd.putstr("azul si es menor a 15kg")
    time.sleep(2)
    lcd.clear()
    lcd.putstr("verde si es menor a 5kg")
    time.sleep(2)
    lcd.clear()
    lcd.putstr("rojo si es defectuoso")
    time.sleep(2)
    lcd.clear()          

while True:
    medicion = float(sensor.read())
    coversion = round (medicion* 60/4096,2)
    print("clasificacion de paquetes")
    utime.sleep_ms(900)

    if conversion > 25:
        ledAmarrillo.value(1)
    else:
        ledAmarrillo.value(0)

    if conversion < 15:
        ledAzul.value(1)
    else:
        ledAmarrillo.value(0)   

    if conversion < 5:
        ledVerde.value(1)
    else:
        ledVerde.value(0)     



esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23
lcd1:GND
lcd1:VCC
lcd1:SDA
lcd1:SCL
r1:1
r1:2
r2:1
r2:2
r3:1
r3:2
pot1:GND
pot1:SIG
pot1:VCC
led1:A
led1:C
led2:A
led2:C
led3:A
led3:C
led4:A
led4:C
r4:1
r4:2