from machine import Pin,I2C
from time import sleep
from i2c_lcd import I2cLcd
i2c=I2C(scl=Pin(22),sda=Pin(21),freq=400000)
lcd=I2cLcd(i2c,0x27,2,16)
led1=Pin(5,Pin.OUT)
led2=Pin(16,Pin.OUT)
led3=Pin(4,Pin.OUT)
ledR=Pin(33,Pin.OUT)
ledG=Pin(25,Pin.OUT)
ledB=Pin(32,Pin.OUT)
btn1=Pin(18,Pin.IN,Pin.PULL_UP)
btn2=Pin(13,Pin.IN,Pin.PULL_UP)
while True :
if btn1.value() == 0 :
lcd.clear()
led1.on()
led2.off()
led3.off()
lcd.move_to(0,0)
lcd.putstr('Green')
lcd.move_to(0,1)
lcd.putstr('ThanakornT2N')
for x in range(5,0,-1):
lcd.move_to(8,0)
lcd.putstr(str(x))
sleep(1)
lcd.clear()
led1.off()
led2.on()
led3.off()
lcd.move_to(0,0)
lcd.putstr('Yellow')
lcd.move_to(0,1)
lcd.putstr('ThanakornT2N')
for x in range(5,0,-1):
lcd.move_to(8,0)
lcd.putstr(str(x))
sleep(1)
lcd.clear()
led1.off()
led2.off()
led3.on()
lcd.move_to(0,0)
lcd.putstr('Red')
lcd.move_to(0,1)
lcd.putstr('ThanakornT2N')
for x in range(5,0,-1):
lcd.move_to(8,0)
lcd.putstr(str(x))
sleep(1)
led1.off()
led2.off()
led3.off()
else :
lcd.move_to(0,0)
lcd.putstr('Light off')
lcd.move_to(0,0)
if btn2.value() == 0 :
lcd.clear()
ledR.on()
ledG.off()
ledB.off()
lcd.move_to(0,0)
lcd.putstr('Green')
lcd.move_to(0,1)
lcd.putstr('ThanakornT2N')
for x in range(5,0,-1):
lcd.move_to(8,0)
lcd.putstr(str(x))
sleep(1)
lcd.clear()
ledR.off()
ledG.on()
ledB.off()
lcd.move_to(0,0)
lcd.putstr('Yellow')
lcd.move_to(0,1)
lcd.putstr('ThanakornT2N')
for x in range(5,0,-1):
lcd.move_to(8,0)
lcd.putstr(str(x))
sleep(1)
lcd.clear()
ledR.off()
ledG.off()
ledB.on()
lcd.move_to(0,0)
lcd.putstr('Red')
lcd.move_to(0,1)
lcd.putstr('ThanakornT2N')
for x in range(5,0,-1):
lcd.move_to(8,0)
lcd.putstr(str(x))
sleep(1)
ledR.off()
ledG.off()
ledB.off()
else :
lcd.move_to(0,0)
lcd.putstr('Light off')
lcd.move_to(0,0)