from machine import Pin
from time import sleep

d7=Pin(23,Pin.OUT)
d6=Pin(22,Pin.OUT)
d5=Pin(21,Pin.OUT)
d4=Pin(19,Pin.OUT)
d3=Pin(18,Pin.OUT)
d2=Pin(5 ,Pin.OUT)
d1=Pin(17,Pin.OUT)
d0=Pin(16,Pin.OUT)
rs=Pin(15,Pin.OUT)
e=Pin(4,Pin.OUT)
boton=Pin(14,Pin.IN,Pin.PULL_UP)

inicializacion=["001100000","001100000","001100000","001110000","000101000","000011000","000001100","000000010"]
MIGUEL=["010011011","010010011","010001111","010101011","010001011","010011001"]
direccion=["100000000","100000010","100000100","100000110","100001000","100001010"]
borrar="000000010"


def pantalla(let):
    d7.value(int(let[0]))
    d6.value(int(let[1]))
    d5.value(int(let[2]))
    d4.value(int(let[3]))
    d3.value(int(let[4]))
    d2.value(int(let[5]))
    d1.value(int(let[6]))
    d0.value(int(let[7]))
    rs.value(int(let[8]))
    e.on()
    sleep(0.1)
    e.off()
  
def palabranormal():
    for j in MIGUEL:
        pantalla(j)
        sleep(1)
    pantalla(borrar)
 
def palabrainvertida():    
    for k in range(len(MIGUEL)-1,-1,-1):
        pantalla(direccion[k])
        pantalla(MIGUEL[k])
        sleep(1)
    pantalla(borrar)

for i in inicializacion:
    pantalla(i)

while(1):
    pantalla("000011100")
    des=boton.value()
    if des==0:
        palabrainvertida()
    else:
        palabranormal()