from machine import ADC, Pin, I2C
from time import sleep
from ssd1306 import SSD1306_I2C
i2c=I2C(0,sda=Pin(8), scl=Pin(9), freq=400000) #initializing the I2C method
oled = SSD1306_I2C(128, 64, i2c)
lux = 26
def readLight(photoGP):
photoRes = machine.ADC(Pin(photoGP))
light = photoRes.read_u16()
#light = round(light/65535*100,2)
return light
while True:
lum = str(readLight(lux))
# Clear the oled display in case it has junk on it.
oled.fill(0)
oled.text("Lux",0,1)
oled.text(lum + " %",0,20)
oled.show()
# Finally update the oled display so the image & text is displayed
oled.show()
sleep(0.5)