Skip to content

Commit cb5f679

Browse files
author
SimonePDA
authored
Merge pull request arduino#223 from per1234/PROGMEM-notes
Replace lost PROGMEM notes and F() documentation
2 parents 189032f + 69a1bbd commit cb5f679

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Language/Variables/Utilities/PROGMEM.adoc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,41 @@ void loop()
165165
}
166166
}
167167
168+
----
169+
[%hardbreaks]
170+
171+
[float]
172+
=== Notes and Warnings
173+
Please note that variables must be either globally defined, OR defined with the static keyword, in order to work with PROGMEM.
174+
175+
The following code will NOT work when inside a function:
176+
177+
[source,arduino]
178+
----
179+
const char long_str[] PROGMEM = "Hi, I would like to tell you a bit about myself.\n";
180+
----
181+
182+
The following code WILL work, even if locally defined within a function:
183+
184+
[source,arduino]
185+
----
186+
const static char long_str[] PROGMEM = "Hi, I would like to tell you a bit about myself.\n"
187+
----
188+
189+
=== The `F()` macro
190+
191+
When an instruction like :
192+
193+
[source,arduino]
194+
----
195+
Serial.print("Write something on the Serial Monitor");
196+
----
197+
198+
is used, the string to be printed is normally saved in RAM. If your sketch prints a lot of stuff on the Serial Monitor, you can easily fill the RAM. If you have free FLASH memory space, you can easily indicate that the string must be saved in FLASH using the syntax:
199+
200+
[source,arduino]
201+
----
202+
Serial.print(F("Write something on the Serial Monitor that is stored in FLASH"));
168203
----
169204

170205
--

0 commit comments

Comments
 (0)