from machine import Pin, I2C, ADC
from ssd1306 import SSD1306_I2C
import time
adc = ADC(Pin(26))
#OLED config
WIDTH =128
HEIGHT= 64
i2c=I2C(0,scl=Pin(1),sda=Pin(0),freq=200000)
oled = SSD1306_I2C(WIDTH,HEIGHT,i2c)
#LED config
redLED = Pin(14, Pin.OUT)
greenLED = Pin(15, Pin.OUT)
#Analog Temp config
while True:
lighting = adc.read_u16()
if lighting > 40000:
redLED.value(1)
greenLED.value(0)
oled.fill(0)
oled.text("Red LED ON", 0, 0)
oled.text('Light:%.2f'%lighting, 0, 30)
oled.show()
time.sleep(2)
#Switching status
else:
time.sleep(1)
redLED.value(0)
greenLED.value(1)
oled.fill(0)
oled.text("Green LED ON", 0, 0)
oled.text('Light:%.2f'%lighting, 0, 30)
oled.show()
time.sleep(2)