原创 Storing Morse code dots and dashes in C

2015-7-31 18:54 1487 21 24 分类: 消费电子

OK, before we begin, let's remind ourselves that I'm a hardware designer by trade. When it comes to software in general -- and C in particular -- I know only enough to be dangerous.

 

I have a project on the go at the moment. This is a secret squirrel project whose purpose -- for the present -- must remain a riddle, wrapped in a mystery, inside an enigma. Suffice it to say that I wish to use a light-emitting diode LED to flash messages in Morse code.

 

My question pertains to the best way in which to represent, store, and access the Morse code dots and dashes used to represent the numbers and letters.

 

 

Ultimately, I want to be able to initialize a string with a message I wish to transmit using a statement like:

 

   char my_string = "HELLO WORLD";

 

Later, I'll pass this string as a parameter into the function that will actually flash the LED. So, once again, my question is: "What's the best way to represent the dots and dashes associated with the various characters?" My very first pass thought was to store these as character strings themselves -- something like the following:

 

   char string_A = ".-";
   char string_B = "-...";
   char string_C = "-.-.";
      :

 

I know that this technique of using a separate character for each dot and dash doesn’t give the smallest memory footprint, but it does have the advantage of understandability, which is, of course, an important consideration. On the other hand, the scheme shown above -- having individual strings for each of the character -- would be difficult to use.

 

The bottom line is that every approach I can think of is less than optimal or incongruous, which is why I'm inviting your ideas. If you think of anything -- preferably pertaining to this perplexing poser -- please post it as a comment below

PARTNER CONTENT

文章评论3条评论)

登录后参与讨论

用户1406868 2015-10-23 14:36

I'll gear this reassess to 2 types of peploe: current Zune owners who are considering an upgrade, and peploe frustrating to decide between a Zune and an iPod. (There are further players worth considering outdated there, comparable the Sony Walkman X, on the contrary I wish this gives you enough facts to make an educated result of the Zune vs players new than the iPod line as well.)

用户3641644 2015-8-5 11:53

How about coding each letter as a series of bits, with a 1 meaning the LED is on, and a 0 meaning it is off. For instance,

A = 10111,

B = 111010101,

...

J = 1011101110111

...

I've shown J as an example because it has one of the longest Morse sequences, coming out at 13 bits by this method. This scheme would allow you to store the Morse equivalent for each letter in two bytes, with leading zeros that are ignored. This seems fairly economical to me.

 

Including numerals in this scheme would be more wasteful, requiring 3 bytes per character (e.g. 19 bits for "0", the longest), but as the Morse equivalent of numerals is more formulaic, you could just leave them out and have your LED flasher function work out their encoding on the fly.

 

Hope this helps!

John

用户3724585 2015-8-3 16:34

My suggestion is pretty basic... you would have an array of arrays (a jagged array).

The major index would represent a character.  Since standard ASCII only allows for a maximum of 256 different 'characters', then you could have this many major indexes (or manipulate the ASCII code passed in to get a truncated index if memory is a big constraint).

Each element of the minor index would then be the length of time that the particular output should be turned on (as compared to the unit time).

This would allow you do code quite easily as

foreach (char c in inp_string)

   foreach (int i in morse_codes[c])

        turn_on_for( i );

        turn_off_for( 1 );

  turn_off_for( 3 );

The morse array for ' ' (space) should be { 0, 0, 0, 0 }, for 'a' should be { 1, 3 }, for 'b' it would be {3, 1, 1, 1} etc

相关推荐阅读
用户3826190 2016-04-29 17:59
Can you improve this BMP display?
Our Caveman Diorama is going to boast a Time Portal, thereby explaining my presence in the scene. ...
用户3826190 2016-04-29 17:56
In progress: Home-made Nixie tube clock
Just to make sure we're all tap dancing to the same drum beat, let's remind ourselves that, someti...
用户3826190 2016-04-29 17:51
Incorporating medication delivery into smartphones
I don’t know about you, but whenever I have to take medications over a period of time, I have a tr...
用户3826190 2016-04-15 17:20
Incredibly handy electronic component testers
Several weeks ago, I was walking around my office building when I ran across my chums Ivan and Dar...
用户3826190 2016-04-15 17:17
A look at electronic component testers
Several weeks ago I was meandering my way around my office building when I ran across my chums Iva...
用户3826190 2016-03-24 11:48
Let Jolly Roger Telephone Co deal with telemarketers
I don’t know about you, but I receive a staggering number of unsolicited telemarketer calls these ...
EE直播间
更多
我要评论
3
21
关闭 站长推荐上一条 /1 下一条