#include <LedControl.h>
// Pines para el controlador de la matriz LED
const int dataIn = 2; // Pin de datos
const int clk = 3; // Pin de reloj
const int cs1 = 4; // Pin de selección del primer controlador
const int cs2 = 5; // Pin de selección del segundo controlador
const int cs3 = 6; // Pin de selección del tercer controlador
const int cs4 = 7; // Pin de selección del cuarto controlador
// Configura los controladores de las matrices LED
LedControl lc1 = LedControl(dataIn, clk, cs1, 4); // Controlador para la primera matriz
LedControl lc2 = LedControl(dataIn, clk, cs2, 4); // Controlador para la segunda matriz
LedControl lc3 = LedControl(dataIn, clk, cs3, 4); // Controlador para la tercera matriz
LedControl lc4 = LedControl(dataIn, clk, cs4, 4); // Controlador para la cuarta matriz
// Pines para los pulsadores
const int buttonUpPin = 8; // Pulsador para aumentar fila
const int buttonDownPin = 9; // Pulsador para disminuir fila
const int buttonRightPin = 10; // Pulsador para aumentar columna
const int buttonLeftPin = 11; // Pulsador para disminuir columna
int selectedRow = 7; // Fila seleccionada (0-15)
int selectedCol = 7; // Columna seleccionada (0-15)
void setup() {
// Inicializa los controladores de las matrices LED
lc1.shutdown(0, false);
lc2.shutdown(0, false);
lc3.shutdown(0, false);
lc4.shutdown(0, false);
lc1.setIntensity(0, 3); // Brillo
lc2.setIntensity(0, 3); // Brillo
lc3.setIntensity(0, 3); // Brillo
lc4.setIntensity(0, 3); // Brillo
lc1.clearDisplay(0); // Limpia la pantalla
lc2.clearDisplay(0); // Limpia la pantalla
lc3.clearDisplay(0); // Limpia la pantalla
lc4.clearDisplay(0); // Limpia la pantalla
// Configura los pulsadores
pinMode(buttonUpPin, INPUT_PULLUP);
pinMode(buttonDownPin, INPUT_PULLUP);
pinMode(buttonRightPin, INPUT_PULLUP);
pinMode(buttonLeftPin, INPUT_PULLUP);
}
void loop() {
// Aumentar fila
if (digitalRead(buttonUpPin) == HIGH) {
selectedRow++;
if (selectedRow > 15) selectedRow = 0; // Vuelve a la fila 0
delay(300); // Debounce
}
// Disminuir fila
if (digitalRead(buttonDownPin) == HIGH) {
selectedRow--;
if (selectedRow < 0) selectedRow = 15; // Vuelve a la fila 15
delay(300); // Debounce
}
// Aumentar columna
if (digitalRead(buttonRightPin) == HIGH) {
selectedCol++;
if (selectedCol > 15) selectedCol = 0; // Vuelve a la columna 0
delay(300); // Debounce
}
// Disminuir columna
if (digitalRead(buttonLeftPin) == HIGH) {
selectedCol--;
if (selectedCol < 0) selectedCol = 15; // Vuelve a la columna 15
delay(300); // Debounce
}
// Actualiza el estado de las matrices
updateMatrix();
}
void updateMatrix() {
// Limpia todas las matrices
lc1.clearDisplay(0);
lc2.clearDisplay(0);
lc3.clearDisplay(0);
lc4.clearDisplay(0);
// Enciende el LED en la posición seleccionada
if (selectedRow < 8) {
lc1.setLed(0, selectedRow, selectedCol, true);
} else if (selectedRow < 16) {
lc2.setLed(0, selectedRow - 8, selectedCol, true);
} else if (selectedRow < 24) {
lc3.setLed(0, selectedRow - 16, selectedCol, true);
} else {
lc4.setLed(0, selectedRow - 24, selectedCol, true);
}
}