from machine import Pin
from time import sleep

def LCD(x):
  D7.value(int(x[0])), D6.value(int(x[1])), D5.value(int(x[2])), D4.value(int(x[3])), RS.value(int(x[4]))
  EN.on()
  sleep(0.5)
  EN.off()

principio = ["00000","00100","00100","10000","00000","00010","00000","11000","00000","01100"]
lista1 = ["00000","00100","01011","10011","01001","01011","01001","01011","01001","11011"]
lista2 = ["11000","00000","00111","01001","01001","01011","01011","01101","01011","00101"]
lista3 = ["00000","00010"]
lista4 = []

D7 = Pin(15,Pin.OUT)
D6 = Pin(2,Pin.OUT)
D5 = Pin(4,Pin.OUT)
D4 = Pin(5,Pin.OUT)
RS = Pin(23,Pin.OUT)
EN = Pin(22,Pin.OUT)
S1 = Pin(12,Pin.OUT)
S2 = Pin(25,Pin.OUT)
S3 = Pin(14,Pin.OUT)

for i in principio:
  LCD(i)

while(1):
  B1=S1.value()
  B2=S2.value()
  B3=S3.value()
  if(B1==1 and B2==0 and B3==0):
    for i in lista1:
      LCD(i)
  elif(B1==0 and B2==1 and B3==0):
    for i in lista2:
      LCD(i)
  elif(B1==0 and B2==0 and B3==1):
    for i in lista3:
      LCD(i)
  else:
    for i in lista4:
      LCD(i)