You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`program memory dataType` - any program memory variable type (see below)
29
+
`dataType` - any variable type
30
30
`variableName` - the name for your array of data
31
31
32
-
Note that because PROGMEM is a variable modifier, there is no hard and fast rule about where it should go, so the Arduino compiler accepts all of the definitions below, which are also synonymous. However experiments have indicated that, in various versions of Arduino (having to do with GCC version), PROGMEM may work in one location and not in another. The "string table" example below has been tested to work with Arduino 13. Earlier versions of the IDE may work better if PROGMEM is included after the variable name.
32
+
Note that because PROGMEM is a variable modifier, there is no hard and fast rule about where it should go, so the Arduino compiler accepts all of the definitions below, which are also synonymous. However experiments have indicated that, in various versions of Arduino (having to do with GCC version), PROGMEM may work in one location and not in another. The "string table" example below has been tested to work with Arduino 13. Earlier versions of the IDE may work better if PROGMEM is included after the variable name.
33
+
34
+
`const dataType variableName[] PROGMEM = {}; // use this form` +
35
+
`const PROGMEM dataType variableName[] = {}; // or this one`+
36
+
`const dataType PROGMEM variableName[] = {}; // not this one
33
37
34
-
`dataType variableName[] PROGMEM = {}; // use this form` +
35
-
`dataType PROGMEM variableName[] = {}; // not this one` +
36
-
`PROGMEM dataType variableName[] = {}; // use this form`
37
38
38
39
While `PROGMEM` could be used on a single variable, it is really only worth the fuss if you have a larger block of data that needs to be stored, which is usually easiest in an array, (or another C data structure beyond our present discussion).
39
40
40
41
Using `PROGMEM` is also a two-step procedure. After getting the data into Flash memory, it requires special methods (functions), also defined in the http://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html[pgmspace.h] library, to read the data from program memory back into SRAM, so we can do something useful with it.
41
42
42
-
As mentioned above, it is important to use the datatypes outlined in http://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html[pgmspace.h]. Some cryptic bugs are generated by using ordinary datatypes for program memory calls. Below is a list of variable types to use. Floating point numbers in program memory do not appear to be supported.
43
-
44
-
`prog_char` - a signed char (1 byte) -127 to 128 +
45
-
`prog_uchar` - an unsigned char (1 byte) 0 to 255 +
46
-
`prog_int16_t` - a signed int (2 bytes) -32,767 to 32,768 +
47
-
`prog_uint16_t` - an unsigned int (2 bytes) 0 to 65,535 +
48
-
`prog_int32_t` - a signed long (4 bytes) -2,147,483,648 to * 2,147,483,647. +
49
-
`prog_uint32_t` - an unsigned long (4 bytes) 0 to 4,294,967,295
50
43
[%hardbreaks]
51
44
--
52
45
// OVERVIEW SECTION ENDS
@@ -69,20 +62,43 @@ The following code fragments illustrate how to read and write unsigned chars (by
0 commit comments