// Codigo Morse: emisor LED para Arduino UNO R3. // A-Z, a-z, 0-9 y espacios. No requiere bibliotecas adicionales. const byte LED_PIN = LED_BUILTIN; const unsigned int DOT_MS = 120; // 10 WPM: 1200 / 10 const char MESSAGE[] = "SOS"; const char* const LETTERS[] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.." }; const char* const DIGITS[] = { "-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----." }; const char* codeFor(char character) { if (character >= 'a' && character <= 'z') character -= 'a' - 'A'; if (character >= 'A' && character <= 'Z') return LETTERS[character - 'A']; if (character >= '0' && character <= '9') return DIGITS[character - '0']; return nullptr; } void sendLetter(const char* code) { for (unsigned int i = 0; code[i] != '\0'; ++i) { if (i > 0) delay(DOT_MS); // Pausa entre senales de una letra: 1 unidad. digitalWrite(LED_PIN, HIGH); delay(code[i] == '.' ? DOT_MS : 3UL * DOT_MS); digitalWrite(LED_PIN, LOW); } } bool sendMessage(const char* message) { // Valida todo antes de emitir: un caracter no admitido cancela el mensaje. bool hasCharacter = false; for (unsigned int i = 0; message[i] != '\0'; ++i) { if (message[i] == ' ') continue; if (codeFor(message[i]) == nullptr) return false; hasCharacter = true; } if (!hasCharacter) return false; bool sent = false; unsigned int gap = 0; for (unsigned int i = 0; message[i] != '\0'; ++i) { if (message[i] == ' ') { if (sent) gap = 7; // Pausa entre palabras: 7 unidades en total. continue; } if (sent) delay(static_cast(gap) * DOT_MS); sendLetter(codeFor(message[i])); sent = true; gap = 3; // Pausa entre letras: 3 unidades en total. } return true; // No anade una pausa de letra al final. } void setup() { pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, LOW); Serial.begin(9600); delay(1000); if (!sendMessage(MESSAGE)) { Serial.println("Usa solo A-Z, 0-9 y espacios; sin tildes ni signos."); } } void loop() { // Una sola transmision. Pulsa RESET para repetir. }