Here is just another fun way to decode Morse... This doesn't blink any lights but just shows the decode from a binary tree.
static char Code[] = " ETIANMSURWDKGOHVF.L.PJBXCYZQ"; //binary MORSE tree blank A-Z
void setup() {
Serial.begin(9600);
Serial.println(MorseOut("Hello World"));
Serial.println(MorseOut("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
}
void loop() {
}
String MorseOut(String MString) {
String codeString = "";
char *text = MString.c_str();
uint8_t index;
while (text[0] != 0) {
index = 28;
if (text[0] > 32) text[0] &= 0xDF; //Convert to uppercase
for (;text[0] != Code[index]; --index); //Find char in binary tree
if (!index) codeString += " "; //Add Space between words
else codeString += getDotDash(index); //Build Code for this character and add to codeString
++text; //Get next character in the string
}
return codeString; //Return Morse code for Mstring as dots dashes and spaces
}
String getDotDash(uint8_t n) {
if (n > 0) return getDotDash((n - 1) / 2) + ((n & 1) ? '.' : '-'); // Recurse binary tree odd=dot even=dash
return " ";
}