Any hams out there that need a quick-and-dirty morse code beacon? Then you might be interested in Mark VandeWettering’s Arduino Based Morse Beacon. I really like the clever way that he stores the code sequences for each character:
It’s a little bit clever (a very little bit) but I guess it does require some explanation. Morse code characters are all length six or less, and each element is either a dot or a dash, so it would seem that we can store the pattern in six bits. Let’s say that dits are zero and dahs are one. Lets store them so the first element gets stored in the least significant bit, and the next in the second most, and so on. The only trick is knowing when there are no elements left, because otherwise we can’t tell (for example) K (-.-) from C (-.-.) To do that, we store a single extra one after all the other elements are taken care of. Then, when we are looping, we do the following. If the pattern is equal to one, we are done (that’s our guard bit). If not, we look at the least significant digit. If it is a zero, we have a dit, if we have a one, it’s a dah. We then get rid of that element (by dividing by two, or shifting right if that floats your boat) and repeat. Voila. Each character takes only a single byte to store its pattern, and decoding is just done in a few instructions.
Mark admits that using an Arduino for this is a bit of overkill, however I think that convenience trumps component cost for one-of projects like this. If you are up for the challenge, however, you could probably build one with more esoteric components, such as an EEPROM+counter, or even a music-box type mechanical system. Anyone create something crazy cool like that?
In the Maker Shed: