from machine import I2C, Pin, ADC
import esp8266_i2c_lcd as esp8266_lcd
from time import sleep
adc32 = ADC(Pin(32))
adc32.atten(ADC.ATTN_11DB)
adc32.width(ADC.WIDTH_10BIT)
i2c = I2C(0) # Using hardware I2C channel 0
lcd = esp8266_lcd.I2cLcd(i2c, esp8266_lcd.DEFAULT_I2C_ADDR, 2, 16)
lcd.clear()
row = dict(zip(range(1016),["'Direct sunlight'"] *31+["'Overcast day'"]*131+ ["'Office light'"]*111+ ["'Stairway lighting'"]*230+ ["Computer monitor'"]*121+["'Twilight'"]*221+["'Deep twilight'"]*132+["'Full moon'"]*30))
while True:
val = adc32.read()
volts = (3.3* val)/1023
if val >= 1015:
val = 1015
lcd.move_to(0,0)
lcd.putstr("ADCvalue: %s" %(row[val]))
lcd.move_to(0,1)
lcd.putstr("Voltage: %0.2f" %(volts))
sleep(1)
input_voltage = "The raw analogue is {} and condition is {}"
print(input_voltage.format(val,row[val]),end = "\r")