Nibbles and Bits
The Care and Feeding of My Pet Arduino
by Budd Churchward - WB7FHC - NIBBLES AND BITS LIBRARY
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 »
Here you go! If you didn't want to figure the remaining letters out yourself, or if things got botched up while you tried, here is what the final string of characters looks like. You can copy it from here, or from the sketch below, and paste it into your project.
char mySet ="##TEMNAIOGKDWRUS##QZYCXBJP#L#FVH09#8###7#######61#######2###3#45";
Notice that we have cleaned this up. Not all of the positions in the string are needed because there are some combinations of dits and dahs that don't represent ANY character. For example: ••-- means nothing in Morse Code. If he hears it, Arduino is going to create the bit stream 00011100, in decimal the number: 28. Well, the letter L is 27 and the letter F is 29. Look at our character set. Right between the L and the F we have inserted a '#'. We have put this symbol in all the places that don't match up with actual characters in Morse Code. If the sender makes a mistake or you are listening to a marginal signal on your receiver, Arduino will print these guys when he can't match the code with the correct letter.
Notice how we see more and more '#####'s strung together as we reach the end of our character set. We have chosen to cut off the set at the number 5. Arduino's bit stream for the '5' would be: 00111111, in decimal the number: 63. We stop there and ignore the punctuation marks. If we continued to use this strategy for them, our character set would be almost twice as long and contain mostly long strings of '#####'s.
To handle the punctuation marks we will check to see if the value of myNum is greater than 63. If it is, we will use a short little proceedure, printPunctuation(), containing half a dozen If statements to match the code to a character and then print it.
Copy and paste the highlighted sections and give it a try. You should end up with a fairly complete set of characters and our project is nearly finished. In the next section, we will add spaces and figure out when to start new lines on our display. Then we will move on to getting our sketch to automatically adjust to the speed of the sender. Until then, Arduino might make a lot of errors copying your code. You can change the value of FullWait to see if you can improve it. Anything as low as 1500 might work for you. When we get to the auto adjusting routines, he will home in on your speed quite quickly.
Next Section »
International Morse Code A •- B -••• C -•-• D -•• E • F ••-• G --• H •••• I •• J •--- K -•- L •-•• M -- N -• O --- P •--• Q --•- R •-• S ••• T - U ••- V •••- W •-- X -••- Y -•-- Z --•• 1 •---- 2 ••--- 3 •••-- 4 ••••- 5 ••••• 6 -•••• 7 --••• 8 ---•• 9 ----• 0 ----- . •-•-•- [period] , --••-- [comma] ? ••--•• [question mark] ! -•-•-- [exclamation mark] @ •--•-• [at sign] - -••••- [hyphen] : ---••• [colon]