Although the preceding example is most consistent with what you know about writing
arrays, it would be more common to write the following:
This is equivalent, and the
*
indicates a pointer. The idea is that
name
points to the first
char
element of the
char
array. That is the memory location that contains the letter
H.
You can rewrite sketch 5-03 to use a variable as well as a string constant, as follows:
A Morse Code Translator
Let’s put together what you have learned about arrays and strings to build a more complex
sketch that will accept any message from the Serial Monitor and flash it out on the built-in
LED.
The letters in Morse code are shown in
Table 5-2
.
Some of the rules of Morse code are that a dash is three times as long as a dot, the time
between each dash or dot is equal to the duration of a dot, the space between two letters is
the same length as a dash, and the space between two words is the same duration as seven
dots.
For
this project, we will
not worry about punctuation, although it would be an
interesting exercise for you to try adding this to the sketch. For a full list of all the Morse
characters, see
en.wikipedia.org/wiki/Morse_code
.