#QUESTION 2
from machine import Pin, ADC
from machine import I2C, Pin
import esp8266_i2c_lcd as esp8266_lcd
from time import sleep
#i2c = I2C(0)
#lcd = esp8266_lcd.I2clcd(i2c, esp8266_lcd.DEFAULT_I2C_ADDR, 2, 16)
#lcd.clear()
adc = ADC(Pin(32))
adc.atten(ADC.ATTN_11DB)
adc.width(ADC.WIDTH_10BIT)
while True:
adc_value = adc.read()
volts = (3.27*adc_value)/1015
if volts < 0.13:
counter = 100000
Micro_II = "Direct sunglight"
elif 0.13 < volts < 0.55:
counter = 10000
Micro_II = "Full daylight"
elif 0.55 < volts < 0.91:
counter = 1000
Micro_II = "Overcast day"
elif 0.91 < volts < 1.65:
counter = 400
Micro_II = "Office lighting"
elif 1.65 < volts < 2.04:
counter = 100
Micro_II = "Stairway lighting"
elif 2.04 < volts < 2.75:
counter = 50
Micro_II = "Computer monitor"
elif 2.75 < volts < 3.18:
counter = 10
Micro_II = "Twilight"
elif 3.18 < volts < 3.27 :
counter = 1
Micro_II = "Deep twilight"
elif volts > 3.27:
counter = 0.1
Micro_II = "Full moon"
lcd.move_to(0,0)
lcd.putstr("ADCvalue:%d" %(adc_value))
lcd.move_to(0,1)
lcd.putstr("volts:%f" % (volts))
condition = " The actual condition is {} and lux value is {:.2f}"
print(condition.format(Micro_II, counter), end = "\r")
sleep(1)