from machine import Pin
import time
 
led = Pin("LED",Pin.OUT) 
ledred = Pin(6,Pin.OUT)
ledgreen = Pin(7,Pin.OUT)
ledblue = Pin(8,Pin.OUT)

boton1 = Pin(18, Pin.IN, Pin.PULL_UP)
boton2 = Pin(19, Pin.IN, Pin.PULL_UP)
boton3 = Pin(20, Pin.IN, Pin.PULL_UP)
boton4 = Pin(21, Pin.IN, Pin.PULL_UP)

def llenado(matx):
    i = 0
    k = 0
    j = 0
    print("INGRESE POR PULSADOR")
    for i in range(3):
        j = 0
        while j<3:
            ban=1
        #for j in range(3):
            led.toggle()
            if boton1.value() == 0:
                print("A[",i,",",j,"]: r", end="")
                print()
                matx[k+j] = "r"   
                ledred.value(1)
                ledgreen.value(0)
                ledblue.value(0)
            elif boton2.value() == 0:
                print("A[",i,",",j,"]: g", end="")
                print()
                matx[k+j] = "g"   
                ledred.value(0)
                ledgreen.value(1)
                ledblue.value(0)
            elif boton3.value() == 0:
                print("A[",i,",",j,"]: b", end="")
                print()
                matx[k+j] = "b"   
                ledred.value(0)
                ledgreen.value(0)
                ledblue.value(10)
            else:
                ban=0
            if ban==1:
                j=j+1
            time.sleep(0.001)
        k = k+3

def operaciones(matx):
    i = 0
    j = 0
    k = 0
    for i in range(3):
        for j in range(3):
            matx[k+j] = matx[k+j]+5
        k = k+3

def despliegue(matx):
    i = 0
    j = 0
    k = 0
    dato="n"
    for i in range(3):
        for j in range(3):
            print(matx[k+j],"  ", end="")
            dato=matx[k+j]
            if dato=="r":
                ledred.value(1)
                ledgreen.value(0)
                ledblue.value(0)
            elif dato=="g":
                ledred.value(0)
                ledgreen.value(1)
                ledblue.value(0)
            elif dato=="b":
                ledred.value(0)
                ledgreen.value(0)
                ledblue.value(1)
            time.sleep(2)

        k = k+3
        print(" ")

mata = int()
mata = [int() for ind0 in range(9)]
if __name__ == '__main__':
    while True:
        # Llenado de Matriz
        llenado(mata)
        # Operaciones sobre la Matriz
        #operaciones(mata)
        # Despliegue de matriz
        despliegue(mata)