PA 19 00 Matriz ledes 8x8

 PA 19 00 Matriz ledes 8x8. Todos ON     Para saber más.

// IMPORTANTE: matriz LEDES de cátodo común.
const int filas[8] = {2, 3, 4, 5, 6, 7, 8, 9};         // Cátodos (filas)
const int columnas[8] = {10, 11, 12, 13, 14, 15, 16, 17}; // Ánodos (columnas)

void setup() {
  for (int i = 0; i < 8; i++) {
    pinMode(filas[i], OUTPUT);
    pinMode(columnas[i], OUTPUT);
  }
}

void loop() {
  for (int i = 0; i < 1000; i++) { // Mantener todos encendidos durante un tiempo
    encenderTodos();
  }
}

void encenderTodos() {
  for (int fila = 0; fila < 8; fila++) {
    // Activar todas las columnas (ánodos)
    for (int col = 0; col < 8; col++) {
      digitalWrite(columnas[col], HIGH);
    }

    // Activar la fila actual (cátodo)
    digitalWrite(filas[fila], LOW);
    delay(2); // Tiempo breve para persistencia visual

    // Apagar la fila antes de pasar a la siguiente
    digitalWrite(filas[fila], HIGH);
  }
}
 PA 19 01 Matriz ledes 8x8. 1 a 1.

// IMPORTANTE: matriz LEDES de cátodo común

// Pines conectados a filas (cátodos)
const int filas[8] = {2, 3, 4, 5, 6, 7, 8, 9};
// Pines conectados a columnas (ánodos)
const int columnas[8] = {10, 11, 12, 13, 14, 15, 16, 17};

void setup() {
  for (int i = 0; i < 8; i++) {
    pinMode(filas[i], OUTPUT);
    pinMode(columnas[i], OUTPUT);
  }

  apagarTodo();
}

void loop() {
  for (int fila = 0; fila < 8; fila++) {
    for (int col = 0; col < 8; col++) {
      apagarTodo(); // Asegura que solo un LED esté encendido

      // Enciende un solo LED (cátodo común: fila LOW, columna HIGH)
      digitalWrite(filas[fila], LOW);     // Activar cátodo
      digitalWrite(columnas[col], HIGH);  // Activar ánodo

      delay(200);
    }
  }
}

void apagarTodo() {
  for (int i = 0; i < 8; i++) {
    digitalWrite(filas[i], HIGH);    // Desactiva cátodos
    digitalWrite(columnas[i], LOW);  // Desactiva ánodos
  }
}

 PA 19 02 Matriz ledes 8x8. Escribe letras.

const int filas[8] = {2, 3, 4, 5, 6, 7, 8, 9};         // Cátodos
const int columnas[8] = {10, 11, 12, 13, 14, 15, 16, 17}; // Ánodos

// Letras en binario
byte H[8] = {
  B10000001,
  B10000001,
  B10000001,
  B11111111,
  B10000001,
  B10000001,
  B10000001,
  B10000001
};

byte O[8] = {
  B00111100,
  B01000010,
  B10000001,
  B10000001,
  B10000001,
  B10000001,
  B01000010,
  B00111100
};

byte L[8] = {
  B00000001,
  B00000001,
  B00000001,
  B00000001,
  B00000001,
  B00000001,
  B00000001,
  B11111111
};

byte A[8] = {
  B00111100,
  B01000010,
  B10000001,
  B10000001,
  B11111111,
  B10000001,
  B10000001,
  B10000001
};

void setup() {
  for (int i = 0; i < 8; i++) {
    pinMode(filas[i], OUTPUT);
    pinMode(columnas[i], OUTPUT);
  }
}

void loop() {
  mostrarLetra(H, 1000); // 1 segundo
  mostrarLetra(O, 1000);
  mostrarLetra(L, 1000);
  mostrarLetra(A, 1000);
}

// Muestra una letra en la matriz por cierto tiempo
void mostrarLetra(byte letra[8], int tiempo) {
  unsigned long t0 = millis();
  while (millis() - t0 < tiempo) {
    for (int fila = 0; fila < 8; fila++) {
      apagarTodo();

      for (int col = 0; col < 8; col++) {
        if (bitRead(letra[fila], 7 - col)) {
          digitalWrite(columnas[col], HIGH); // Ánodo
        } else {
          digitalWrite(columnas[col], LOW);
        }
      }

      digitalWrite(filas[fila], LOW); // Cátodo activo
      delay(2);
      digitalWrite(filas[fila], HIGH);
    }
  }
}

// Apaga toda la matriz
void apagarTodo() {
  for (int i = 0; i < 8; i++) {
    digitalWrite(filas[i], HIGH);   // Desactiva cátodos
    digitalWrite(columnas[i], LOW); // Desactiva ánodos
  }
}


 PA 19 03 Matriz ledes 8x8. Escribe números.

const int filas[8] = {2, 3, 4, 5, 6, 7, 8, 9};
const int columnas[8] = {10, 11, 12, 13, 14, 15, 16, 17};

// Números del 0 al 9, centrados (6x6) y ya reflejados horizontalmente
byte numeros[10][8] = {
  { B00000000, B00011100, B00100010, B00100010, B00100010, B00100010, B00011100, B00000000 }, // 0
  { B00000000, B00001000, B00001100, B00001000, B00001000, B00001000, B00011100, B00000000 }, // 1
  { B00000000, B00011100, B00100010, B00100000, B00011000, B00000100, B00111110, B00000000 }, // 2
  { B00000000, B00011100, B00100010, B00011000, B00100000, B00100010, B00011100, B00000000 }, // 3
  { B00000000, B00010000, B00011000, B00010100, B00010010, B00111110, B00010000, B00000000 }, // 4
  { B00000000, B00111110, B00000010, B00011110, B00100000, B00100010, B00011100, B00000000 }, // 5
  { B00000000, B00011100, B00000010, B00011110, B00100010, B00100010, B00011100, B00000000 }, // 6
  { B00000000, B00111110, B00100000, B00010000, B00001000, B00001000, B00001000, B00000000 }, // 7
  { B00000000, B00011100, B00100010, B00011100, B00100010, B00100010, B00011100, B00000000 }, // 8
  { B00000000, B00111000, B01000100, B01000100, B01111000, B01000000, B00111100, B00000000 }  // 9
};

void setup() {
  for (int i = 0; i < 8; i++) {
    pinMode(filas[i], OUTPUT);
    pinMode(columnas[i], OUTPUT);
  }
}

void loop() {
  for (int i = 0; i < 10; i++) {
    mostrarNumero(numeros[i], 1000);  // Mostrar cada número 1 segundo
  }
}

void mostrarNumero(byte numero[8], int tiempo) {
  unsigned long inicio = millis();
  while (millis() - inicio < tiempo) {
    for (int fila = 0; fila < 8; fila++) {
      apagarTodo();

      for (int col = 0; col < 8; col++) {
        if (bitRead(numero[fila], 7 - col)) {
          digitalWrite(columnas[col], HIGH); // Encender LED
        } else {
          digitalWrite(columnas[col], LOW);  // Apagar LED
        }
      }

      digitalWrite(filas[fila], LOW);  // Activar fila
      delay(2);
      digitalWrite(filas[fila], HIGH); // Desactivar fila
    }
  }
}

void apagarTodo() {
  for (int i = 0; i < 8; i++) {
    digitalWrite(filas[i], HIGH);   // Cátodo apagado
    digitalWrite(columnas[i], LOW); // Ánodo apagado
  }
}