import time
from machine import I2C,SoftI2C,Pin, ADC
from pico_i2c_lcd import I2cLcd
import math
# freq 4000-5000 for banner type behaviour
i2c=SoftI2C(sda=Pin(1),scl=Pin(2),freq=500000)
lcd_address=i2c.scan()[0]
lcd = I2cLcd(i2c, lcd_address, 2, 16)
adc = ADC(26)
adcp= ADC(27)
BETA=3950
GAMMA = 0.7
RL10 = 50
while True:
temp=adc.read_u16()
photo_reading=adcp.read_u16()
voltage = photo_reading / 65535. * 5;
resistance = 2000 * voltage / (1-voltage / 5);
lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA))
celsius = 1 / (math.log(1 / (65535. / temp - 1)) / BETA + 1.0 / 298.15) - 273.15;
print(celsius)
lcd.clear()
lcd.putstr(str(round((celsius),2))+" *C" +"\n"+ str(round(lux,2))+" lux")
time.sleep(1)
lcd.clear()
time.sleep(0.1)
lcd=I2cLcd(i2c,lcd_address,2,16)
lcd.putstr("Amitesh")