from machine import Pin, I2C, ADC
from lcd_api import LcdApi
from pico_i2c_lcd import I2cLcd
import utime
ADC_VREF_mV = 5000.0
ADC_RESOLUTION = 1024.0
PIN_LM35 = 14
adc = ADC(Pin(PIN_LM35))
lcd = I2cLcd(I2C(0), 0x27, 2, 16)
def convertir_temperatura(adc_value):
milliVolt = adc_value * (ADC_VREF_mV / ADC_RESOLUTION)
tempC = milliVolt / 10
tempF = tempC * 9 / 5 + 32
return tempC, tempF
def main():
while True:
adc_value = adc.read()
tempC, tempF = convertir_temperatura(adc_value)
lcd.move_to(0, 0)
lcd.putstr("{:.2f}°C".format(tempC))
lcd.move_to(0, 1)
lcd.putstr("{:.2f}°F".format(tempF))
print("{:.2f}°C ~ {:.2f}°F".format(tempC, tempF))
utime.sleep(0.5)
if __name__ == "__main__":
main()