The purpose of this command is to tell the compiler to use the
pgmspace
library for this
sketch. In this case, a library is a set of functions that someone else has written and that
you can use in your sketches without having to understand all the details of how those
functions work.
Because you are using this library, the
PROGMEM
keyword and the
pgm_read_word
function are available. You will use both in the sketches that follow.
This library is included as part of the Arduino software and
is an officially supported
Arduino library. A good collection of such official libraries is available, and many
unofficial
libraries, developed by people like you and made for others to use, are also
available on the Internet. Such unofficial libraries must be
installed into your Arduino
environment. You will learn more about these libraries, as well as how to write your own
libraries, in
Chapter 11
.
When using
PROGMEM
, you have to make
sure that you use special
PROGMEM
-
friendly data types. Unfortunately, that does
not
include
an array of
char
arrays. You
actually have to define a variable for each string using a
PROGMEM
string type and then
put them all in a
PROGMEM
array type, like this:
I have not listed sketch 8-01 here, as it is a little lengthy, but you may wish to load it
and verify that it works the same way as the RAM-based version.
In addition to creating the data in a special way, you also have to read the data back a
special way. Your code to get the code string for a Morse letter from the array has to be
modified to look like this:
This uses a
Dostları ilə paylaş: