""" This program reads the value of the PI's on-board temperature sensor, an externally connect pot, and a push button and processes these values and writes these values to a 16X2 LCD display """ from machine import I2C, ADC, Pin from time import sleep from pico_i2c_lcd import I2cLcd i2c = I2C(0, sda=Pin(16), scl=Pin(17), freq=400000) #i2c connection to Pi temp_sensor = ADC(4) # Default connection of temperature sensor pot1 = machine.ADC(28) #Analog input connection to Pi button1 = Pin(12,Pin.IN,Pin.PULL_DOWN) #GPIO connection to Pi I2C_ADDR = i2c.scan()[0] lcd = I2cLcd(i2c, I2C_ADDR, 2, 16) lcd.backlight_on() def temperatureC(): # get raw sensor data raw_sensor_data = temp_sensor.read_u16() # convert raw value to equivalent voltage sensor_voltage = (raw_sensor_data / 65535)*3.3 # convert voltage to temperature (celcius) temperatureC = 27 - (sensor_voltage - 0.706)/0.001721 return temperatureC while True: tempC = int(temperatureC()) tempF = int(tempC*1.8+32) pot2 = pot1.read_u16() #read the pot value pot2 = int(pot2/1300) #scale the pot value between 0 and 50 if pot2 <= 1: pot2 = int(1) #Keep the pot value positive button = int(10) if not button1.value(): #if the push button is not pressed button = int(10) # 'button' is 10. If the push button if button1.value(): # is pressed 'button' is 20 button = int(20) lcd.putstr("Temp="+str(tempC)+"C ") #send variables to the lcd.putstr("Pot="+str(pot2)+"\n") #LCD display lcd.putstr("Button="+str(button)) sleep(1) lcd.clear() #Clear the display