import machine
from machine import SoftI2C, Pin, ADC
from lcd_api import LcdApi
from i2c_lcd import I2cLcd
import utime
I2C_ADDR = 0x27
totalRows = 2
totalColumns = 16
i2c = SoftI2C(scl=Pin(22), sda=Pin(21), freq=10000)
# Initialize the LCD
lcd = I2cLcd(i2c, I2C_ADDR, totalRows, totalColumns)
# Create an ADC object for pin 34
adc = ADC(Pin(34))
while True:
sensorValue = adc.read_u16()
voltage = (sensorValue * (5/65535))
print(voltage)
resistance = 10000*voltage / (5 - voltage)
# Display resistance on LCD
lcd.move_to(0, 0)
lcd.putstr("LDR Resistance: {:.0f} Ohms".format(resistance))
# Delay for half a second
utime.sleep(0.5)