Skip to content

Commit 70b488e

Browse files
committed
Fixed PROGMEM example, and updated for modern IDE.
An example in the PROGMEM documentation uses `strlen` instead of `strlen_P` to access data stored using PROGMEM. Also, since version 1.0 of the IDE (2011) the file `avr/pgmspace.h` no longer needs to be included (Added to Arduino.h).
1 parent 2773e7d commit 70b488e

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

Language/Variables/Utilities/PROGMEM.adoc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Store data in flash (program) memory instead of SRAM. There's a description of t
1616

1717
The `PROGMEM` keyword is a variable modifier, it should be used only with the datatypes defined in pgmspace.h. It tells the compiler "put this information into flash memory", instead of into SRAM, where it would normally go.
1818

19-
PROGMEM is part of the http://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html[pgmspace.h] library. So you first need to include the library at the top your sketch, like this:
19+
PROGMEM is part of the http://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html[pgmspace.h] library. It is included automatically in modern versions of the IDE, however if you are using an IDE version below 1.0 (2011), you'll first need to include the library at the top your sketch, like this:
2020

2121
`#include <avr/pgmspace.h>`
2222
[%hardbreaks]
@@ -58,9 +58,6 @@ The following code fragments illustrate how to read and write unsigned chars (by
5858

5959
[source,arduino]
6060
----
61-
#include <avr/pgmspace.h>
62-
63-
6461
// save some unsigned ints
6562
const PROGMEM uint16_t charSet[] = { 65000, 32796, 16843, 10, 11234};
6663
@@ -86,7 +83,7 @@ void setup() {
8683
Serial.println();
8784
8885
// read back a char
89-
for (k = 0; k < strlen(signMessage); k++)
86+
for (k = 0; k < strlen_P(signMessage); k++)
9087
{
9188
myChar = pgm_read_byte_near(signMessage + k);
9289
Serial.print(myChar);

0 commit comments

Comments
 (0)