/*
Arduino | coding-help
Morse Code on Pin 13 LED (Arduino Uno)
Halcyon
January 19, 2026 at 8:18 PM
*/
int16_t element = 10; //In hundreds of ms, change to make timing faster or slower. Dot is 1 unit, dash is 3, word break is 7
// Make ^ larger if you have trouble reading the flashes
String inputStr = "KF8ETG Hello World 2026"; //My call sign, Peter Ver Duin, KF8ETG
int inLen = 0;
char* morse_code;
char *alphaArr[26] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.." };
char *numbsArr[10] = { "-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----." };
void dot(int16_t duration) {
digitalWrite(13, HIGH);
delay(duration * 100);
digitalWrite(13, LOW);
delay(duration * 100);
}
void dash(int16_t duration) {
digitalWrite(13, HIGH);
delay(duration * 300);
digitalWrite(13, LOW);
delay(duration * 100);
}
void space(int16_t duration) {
digitalWrite(13, LOW);
delay(duration * 700);
}
void setup() {
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop() {
// Serial.println("Enter the string to flash:");
// while (Serial.available() == 0) {}
// inputStr = Serial.readString();
// Uncomment these three lines to allow flashing of any input (alphanumeric characters and space only)
Serial.println(inputStr);
inLen = inputStr.length();
for (int i = 0; i < inLen; i++) { // convert to morse
if (isUpperCase(inputStr[i])) {
morse_code = alphaArr[inputStr[i] - 'A'];
}
else if (isLowerCase(inputStr[i])) {
morse_code = alphaArr[inputStr[i] - 'a'];
}
else if (isDigit(inputStr[i])) {
morse_code = numbsArr[inputStr[i] - '0'];
}
else if (isSpace(inputStr[i])) {
morse_code = "/";
}
else {
Serial.print("No International Morse for ");
Serial.print(inputStr[i]);
Serial.print(" ");
}
Serial.print(morse_code);
Serial.print(" "); // comment out this line and the one above to remove the terminal output and purely flash the code
for (int j = 0; j < strlen(morse_code); ++j) {
if (morse_code[j] == '.') {
dot(element);
}
else if (morse_code[j] == '-') {
dash(element);
}
else {
space(element);
}
}
}
Serial.println();
}