import board
import pulseio
import adafruit_irremote
import neopixel
import time
# Configuracion de la matriz LED 8x8
pixel = neopixel.NeoPixel(board.GP15, 64, brightness=0.1, auto_write=False)
#
pixel.fill((0, 0, 0))
pixel.show()
# Configuracion del receptor IR
ir_pin = pulseio.PulseIn(board.GP16, maxlen=200, idle_state=True)
decoder = adafruit_irremote.GenericDecode()
# Estado de las filas
fila1 = False
fila2 = False
fila3 = False
fila4 = False
fila5 = False
fila6 = False
fila7 = False
fila8 = False
blanco = False
last_time = 0
last_command = None
print("Esperando señal IR del control...")
#Inicio del programa
while True:
try:
pulses = decoder.read_pulses(ir_pin)
if not pulses:
continue
code = decoder.decode_bits(pulses)
if len(code) < 3:
continue
command = code[2]
now = time.monotonic()
# Evitar repeticiones del control
if command == last_command and now - last_time < 0.3:
continue
print("Comando recibido:", hex(command))
# Tecla 0
if command == 0x16:
blanco = not blanco
print("Matriz blanca:", blanco)
# Tecla 1
elif command == 0x0C:
fila1 = not fila1
blanco = False
print("Fila 1 Roja:", fila1)
# Tecla 2 - Fila VERDE
elif command == 0x18:
fila2 = not fila2
blanco = False
print("Fila 2 Verde:", fila2)
# Tecla 3 - Fila AZUL
elif command == 0x5E:
fila3 = not fila3
blanco = False
print("Fila 3 Azul:", fila3)
# Tecla 4 - Fila MORADA
elif command == 0x11:
fila4 = not fila4
blanco = False
print("Fila 4 Morada:", fila4)
# Tecla 5 - Fila NARANJA
elif command == 0x1d:
fila5 = not fila5
blanco = False
print("Fila 5 Naranja:", fila5)
# Tecla 6 - Fila AMARILLA
elif command == 0x5A:
fila6 = not fila6
blanco = False
print("Fila 6 Amarilla:", fila6)
# Tecla 7 - Fila ROSA
elif command == 0x42:
fila7 = not fila7
blanco = False
print("Fila 7 Rosa:", fila7)
# Tecla 8 - Fila AZUL/VERDE
elif command == 0x52:
fila8 = not fila8
blanco = False
print("Fila 8 Azul/Verde:", fila8)
else:
continue
last_time = now
last_command = command
# Actualizacion de la matriz
pixel.fill((0, 0, 0))
if blanco:
pixel.fill((255, 255, 255))
else:
if fila1:
pixel[0:8] = [(255, 0, 0)] * 8
if fila2:
pixel[8:16] = [(0, 255, 0)] * 8
if fila3:
pixel[16:24] = [(0, 0, 255)] * 8
if fila4:
pixel[24:32] = [(128, 0, 255)] * 8
if fila5:
pixel[32:40] = [(255, 100, 0)] * 8
if fila6:
pixel[40:48] = [(255, 255, 0)] * 8
if fila7:
pixel[48:56] = [(255, 20, 147)] * 8
if fila8:
pixel[56:64] = [(0, 255, 255)] * 8
pixel.show()
except adafruit_irremote.IRNECRepeatException:
pass
except adafruit_irremote.IRDecodeException:
pass
except Exception as e:
print("Error:", e)
time.sleep(0.1)