PA 18 00 Matriz. Display7segmentos (5011AS). Números
// Pines conectados a los segmentos A-G
int segmentos[] = {2, 3, 4, 5, 6, 7, 8};
// Dígitos del 0 al 9 en formato binario (0 = apagado, 1 = encendido)
byte numeros[10][7] = {
{1, 1, 1, 1, 1, 1, 0}, // 0
{0, 1, 1, 0, 0, 0, 0}, // 1
{1, 1, 0, 1, 1, 0, 1}, // 2
{1, 1, 1, 1, 0, 0, 1}, // 3
{0, 1, 1, 0, 0, 1, 1}, // 4
{1, 0, 1, 1, 0, 1, 1}, // 5
{1, 0, 1, 1, 1, 1, 1}, // 6
{1, 1, 1, 0, 0, 0, 0}, // 7
{1, 1, 1, 1, 1, 1, 1}, // 8
{1, 1, 1, 1, 0, 1, 1} // 9
};
void setup() {
for (int i = 0; i < 7; i++) {
pinMode(segmentos[i], OUTPUT);
}
}
void loop() {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 7; j++) {
digitalWrite(segmentos[j], numeros[i][j]);
}
delay(1000); // Espera 1 segundo antes del siguiente número
}
}
PA 18 01 Matriz. Display 7 segmentos. Puerto serie.
int segmentos[] = {2, 3, 4, 5, 6, 7, 8};
// Dígitos del 0 al 9 (1 = encendido, 0 = apagado)
byte numeros[10][7] = {
{1, 1, 1, 1, 1, 1, 0}, // 0
{0, 1, 1, 0, 0, 0, 0}, // 1
{1, 1, 0, 1, 1, 0, 1}, // 2
{1, 1, 1, 1, 0, 0, 1}, // 3
{0, 1, 1, 0, 0, 1, 1}, // 4
{1, 0, 1, 1, 0, 1, 1}, // 5
{1, 0, 1, 1, 1, 1, 1}, // 6
{1, 1, 1, 0, 0, 0, 0}, // 7
{1, 1, 1, 1, 1, 1, 1}, // 8
{1, 1, 1, 1, 0, 1, 1} // 9
};
void setup() {
Serial.begin(9600); // Iniciar el monitor serie
for (int i = 0; i < 7; i++) {
pinMode(segmentos[i], OUTPUT);
}
Serial.println("Introduce un número del 0 al 9:");
}
void loop() {
if (Serial.available() > 0) {
char entrada = Serial.read();
if (entrada >= '0' && entrada <= '9') {
int numero = entrada - '0';
for (int i = 0; i < 7; i++) {
digitalWrite(segmentos[i], numeros[numero][i]);
}
Serial.print("Mostrando número: ");
Serial.println(numero);
} else {
Serial.println("Por favor introduce un número válido (0-9).");
}
}
}
PA 18 02 Matriz. Display 7 segmentos. Keypad.
#include <Keypad.h>
// Pines para los segmentos A-G del display
int segmentos[] = {2, 3, 4, 5, 6, 7, 8};
// Dígitos del 0 al 9 (1 = encendido, 0 = apagado)
byte numeros[10][7] = {
{1, 1, 1, 1, 1, 1, 0}, // 0
{0, 1, 1, 0, 0, 0, 0}, // 1
{1, 1, 0, 1, 1, 0, 1}, // 2
{1, 1, 1, 1, 0, 0, 1}, // 3
{0, 1, 1, 0, 0, 1, 1}, // 4
{1, 0, 1, 1, 0, 1, 1}, // 5
{1, 0, 1, 1, 1, 1, 1}, // 6
{1, 1, 1, 0, 0, 0, 0}, // 7
{1, 1, 1, 1, 1, 1, 1}, // 8
{1, 1, 1, 1, 0, 1, 1} // 9
};
// Letras A-D (1 = encendido, 0 = apagado)
byte letras[4][7] = {
{1, 1, 1, 0, 1, 1, 1}, // A
{0, 0, 1, 1, 1, 1, 1}, // B
{1, 0, 0, 1, 1, 1, 0}, // C
{0, 1, 1, 1, 1, 0, 1} // D
};
// --- Configuración del Keypad 4x4 ---
const byte FILAS = 4;
const byte COLUMNAS = 4;
char teclas[FILAS][COLUMNAS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte pinesFilas[FILAS] = {9, 10, 11, 12}; // Ajusta según tu conexión
byte pinesColumnas[COLUMNAS] = {A0, A1, A2, A3}; // Ajusta según tu conexión
Keypad keypad = Keypad(makeKeymap(teclas), pinesFilas, pinesColumnas, FILAS, COLUMNAS);
// -------------------------------------
void setup() {
for (int i = 0; i < 7; i++) {
pinMode(segmentos[i], OUTPUT);
}
}
void loop() {
char tecla = keypad.getKey();
if (tecla) {
if (tecla >= '0' && tecla <= '9') {
int numero = tecla - '0'; // Convertir char a número
for (int i = 0; i < 7; i++) {
digitalWrite(segmentos[i], numeros[numero][i]); // Mostrar el número
}
}
else if (tecla >= 'A' && tecla <= 'D') {
int letraIndex = tecla - 'A'; // Convertir 'A' a 0, 'B' a 1, etc.
for (int i = 0; i < 7; i++) {
digitalWrite(segmentos[i], letras[letraIndex][i]); // Mostrar la letra
}
}
else {
// Si se presiona una tecla que no sea número o letra válida, apagar display
for (int i = 0; i < 7; i++) {
digitalWrite(segmentos[i], LOW);
}
}
}
}