Programming Arduino Getting Started with Sketches


PROGMEN ; it lives in a library and is a bit awkward to use. The PROGMEM Directive



Yüklə 5,42 Kb.
Pdf görüntüsü
səhifə59/78
tarix22.12.2023
ölçüsü5,42 Kb.
#189286
1   ...   55   56   57   58   59   60   61   62   ...   78
Arduino SimonMonk 2011

PROGMEN
; it lives in a
library and is a bit awkward to use.
The PROGMEM Directive
To store your data in flash memory, you have to include the 
PROGMEM
library as
follows:


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 

Yüklə 5,42 Kb.

Dostları ilə paylaş:
1   ...   55   56   57   58   59   60   61   62   ...   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