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)