I'm trying to think of a way to make my Arduino Mega pick a random word from a list, flash all the segments of an LCD in the morse code for that word, then give me a few seconds to try to guess the word, then the LCD would display the word.
I'm looking for a good method to store and access the morse code for each letter. I like the idea of a binary code that starts with a one, then has zeroes and ones for dots and dashes, respectively. For example, "P" (dot dash dash dot) would be 0b10110.
I was thinking to have a long array of words, pick one at random, then access each letter in the word in a for loop. I'm just not sure how to use the letter as a key to access the binary morse integer.
I guess I could use a whole lot of if else statements, but that doesn't sound efficient or pretty. I was thinking to use some sort of map or lookup table, but I saw other posts saying that a map is kind of resource intensive for an Arduino.
Ideas are good. Characters have numerical values already, see ASCII code for that.
The Morse patterns could be in an array big enough for all the characters you are interested in.
The ASCII code numerical equivalent of a character could be used as an index into that array.
You could do some calculations. 'A' is 65, any letter after that is just one more, so a character minus 'A' or 65 would be an index 0 to 25 for the 26 letters A..Z.
I have an LCD that I can output words onto and turn on and off. I think I can figure out how to use my little binary code to turn the segments on and off at the correct times.
Besides the timing to dots and dashes, you also need to get the timing correct for the space between letters and the space between words. There are many dozens of Arduino related code around that produce Morse code sounds and you can easily convert to light flashing.
It shouldn't be too hard. Between letters is the length of three dots and between words is length of seven dots. I may take a look how others have done it, though.
Because Magic Morse is a true algorithm, commonly implemented tree-searches are not applicable... every Morse character is an integer which can be reversed back to Morse dots/dashes.
The Excel snippet shows that by using the DAH as the primary weighting element, a simple algorithm can be constructed for decoding Morse Code into a unique index in the range of 0-255. DAH's are weighted by received position in the stream and DAH's and DIT's are counted and stored in 3-bits to represent the number of Morse elements in a character. When the DAH weighting is added to the DIT+DAH counts, a unique number is created... called Magic Morse.
Yeah, this seems like a good strategy. Is there an advantage to your algorithm that encodes the length of the code in the magic morse number, as opposed to what I was thinking, where the first one in the binary number signals that the code is made up of the number of remaining bits? I was thinking a for loop that starts at the leftmost bit and scans right until it sees a one, then it would know the length from what's left over.
Nice to have a bidirectional algorithm to base everything on: I have a ping pong ball with LEDs inside that blink the temperature every 30 seconds... red, blue, green represents the 3 ranges inside the living room:
R 89 - 80
G 79 - 70
B 69 - 60
$1 mirror from dollar store; sits on battery pack. Sticky copper tape used for conductors .. ugly bug-style point-point wiring for tiny85... covered in conformal epoxy just like military repairs