Programming Arduino Getting Started with Sketches


Table 5-2 Morse Code Letters Data



Yüklə 5,42 Kb.
Pdf görüntüsü
səhifə41/78
tarix22.12.2023
ölçüsü5,42 Kb.
#189286
1   ...   37   38   39   40   41   42   43   44   ...   78
Arduino SimonMonk 2011

Table 5-2
Morse Code Letters
Data
You are going to build this example a step at a time, starting with the data structure that
you are going to use to represent the codes.
It is important to understand that there is no one solution to this problem. Different
programmers will come up with different ways to solve it. So, it is a mistake to think to
yourself, “I would never have come up with that.” Well, no, quite possibly you would
come up with something different and better. Everyone thinks in different ways, and this
solution happens to be the one that first popped into the author’s head.
Representing the data is all about finding a way of expressing 
Table 5-2
 in C. In fact,
you are going to split the data into two tables: one for the letters, and one for the numbers.
The data structure for the letters is as follows:
What you have here is an array of string literals. So, because a string literal is actually
an array of 
char
, what you actually have here is an array of arrays—something that is
perfectly legal and really quite useful.
This means that to find Morse for 
A
, you would access 
letters[0]
, which would give you
the string 
.-
. This approach is not terribly efficient, because you are using a whole byte


(eight bits) of memory to represent a dash or a dot, which could be represented in a bit.
However, you can easily justify this approach by saying that the total number of bytes is
still only about 90 and we do have 2K to play with. Equally importantly, it makes the code
easy to understand.
Numbers use the same approach:
Globals and Setup
You need to define a couple of global variables: one for the delay period for a dot, and one
to define which pin the LED is attached to:
The 

Yüklə 5,42 Kb.

Dostları ilə paylaş:
1   ...   37   38   39   40   41   42   43   44   ...   78




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin