#include <LiquidCrystal.h>
// Pines del ESP32 conectados a la pantalla LCD
#define LCD_RS 22
#define LCD_E 23
#define LCD_D4 5
#define LCD_D5 18
#define LCD_D6 19
#define LCD_D7 21
// Inicializamos la pantalla LCD
LiquidCrystal lcd(LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
// Tabla de códigos Morse
const char* morseAlphabet[] = {
".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."
};
// Letras del alfabeto
const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// Función para convertir un caracter Morse a su letra equivalente
char morseToChar(const char* morseCode) {
for (int i = 0; i < 26; i++) {
if (strcmp(morseAlphabet[i], morseCode) == 0) {
return alphabet[i];
}
}
return ' ';
}
void setup() {
// Inicializamos la pantalla LCD
lcd.begin(16, 2);
lcd.setCursor(0, 0);
Serial.begin(9600);
}
void loop() {
// Recibimos el código Morse por el puerto serial
String morseCode = Serial.readStringUntil('\n');
// Convertimos el código Morse a texto en español
String spanishText = "";
char* token = strtok((char*)morseCode.c_str(), " ");
while (token != NULL) {
spanishText += morseToChar(token);
token = strtok(NULL, " ");
}
// Mostramos el texto en la pantalla LCD
lcd.clear();
lcd.print(spanishText);
// Esperamos un poco
delay(1000);
//-.- .- .-.. . -...
}