from machine import Pin,Timer,I2C
import utime as ut
from pico_i2c_lcd import I2cLcd



led1=Pin(3,Pin.OUT)
led2=Pin(4,Pin.OUT)
led3=Pin(5,Pin.OUT)


sda=Pin(0)
scl=Pin(1)

i2c=I2C(0,sda=sda,scl=scl,freq=400000)

device=i2c.scan()

i2caddr=device[0]

lcd=I2cLcd(i2c,i2caddr,2,16)


while True:
    tt=[[0,0],[0,1],[1,0],[1,1]]
    tt_and=[0,0,0,1]
    tt_or=[0,1,1,1]
    tt_xor=[0,1,1,0]
    ot=0

    print('And gate')
    for inp in tt:
        led1.value(inp[0])
        led2.value(inp[1])
        led3.value(tt_and[ot])
        lcd.clear()
        lcd.putstr("AND "+str(inp[0])+"  "+str(inp[1])+" "+str(tt_and[ot]))
        ot+=1
        ut.sleep(2)
        lcd.clear()
    ot=0
    print('Now,or gate')
    for inp in tt:
        led1.value(inp[0])
        led2.value(inp[1])
        led3.value(tt_or[ot])
        lcd.clear()
        lcd.putstr("OR "+str(inp[0])+"  "+str(inp[1])+" "+str(tt_or[ot]))
        ot+=1
        ut.sleep(2)
        lcd.clear()
    ot=0
    print('Now,xor gate')
    for inp in tt:
        led1.value(inp[0])
        led2.value(inp[1])
        led3.value(tt_xor[ot])
        lcd.clear()
        lcd.putstr("XOR "+str(inp[0])+"  "+str(inp[1])+" "+str(tt_xor[ot]))
        ot+=1
        ut.sleep(2)
        lcd.clear()


#timer=Timer(period=300,mode=Timer.PERIODIC,callback=fn)
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT