""" Program 12-4: Thermometer display using SSD1306 OLED""" import time from machine import ADC, Pin from ssd1306 import SSD1306 # Instatiate a display object display = SSD1306() # Thermometer code from Program 7-3 LM34 = ADC(Pin(27)) # instantiate an ADC object using GP27 pin. while True: value = LM34.read_u16() # read a conversion result value &= 0xFFF0 # mask out the lower bits mV = value * 3300 / 65520 # convert to millivolts temp = mV / 10 # LM34 has the output of 10mV per degree F temp_text = f'{temp:3.1f} F' # MicroPython v1.17 or later print(temp_text) # display temperature at REPL terminal # Display temperature on the OLED display.fill(display.BLACK) display.text('Temperature', 15, 20, display.WHITE) display.text(temp_text, 35, 40, display.WHITE) display.flush() time.sleep(1)