import re
from math import log
from micropython import const as cnst
from machine import Pin, ADC
from utime import sleep_ms, ticks_ms
from esp32_gpio_lcd import GpioLcd

prev_tempInt = None
prev_tempExt = None

internalTemp = ADC(Pin(26))  # ADC channel 0
externalTemp = ADC(Pin(27))  # ADC channel 1
BETA = 3950

print(f"analog {internalTemp}")
print(f"analog {externalTemp}")

def test_main():
    """Test function for verifying basic functionality."""
    global prev_tempInt, prev_tempExt  # Declare prev_temp as a global variable
    print("Running test_main")
    lcd = GpioLcd(rs_pin=Pin(4),
                  enable_pin=Pin(15),
                  d4_pin=Pin(5),
                  d5_pin=Pin(18),
                  d6_pin=Pin(21),
                  d7_pin=Pin(22),
                  num_lines=2, num_columns=20)
    lcd.clear()
    count = 0
    while True:
        analog_value1 = internalTemp.read_u16()
        analog_value2 = externalTemp.read_u16()
        Temp1 = 1 / (log(1 / (65535 / analog_value1 - 1)) / BETA + 1 / 298.15) - 273.15 
        Temp2 = 1 / (log(1 / (65535 / analog_value2 - 1)) / BETA + 1 / 298.15) - 273.15 
        if (Temp1 != prev_tempInt) or (Temp2 != prev_tempExt):
            print(f"Internal {str(Temp1)[:5]}\nexternal {str(Temp2)[:5]}")
            prev_tempInt = Temp1
            prev_tempExt = Temp2
        lcd.move_to(0, 0)
        lcd.putstr(f"Internal {str(Temp1)[:5]}\nexternal {str(Temp2)[:5]}")
        sleep_ms(1000)
        count += 1

test_main()
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT