mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-21 10:26:06 +03:00
Update PROGMEM.rst (#6872)
* Update PROGMEM.rst Include array of strings in the description, since the examples in Arduino do not consider the right pointer size * Update PROGMEM.rst
This commit is contained in:
parent
e08b22c5b5
commit
5aefed2f4b
@ -237,6 +237,42 @@ the value back.
|
||||
}
|
||||
}
|
||||
|
||||
How do I declare Arrays of strings in PROGMEM and retrieve an element from it.
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
It is often convenient when working with large amounts of text, such as a project with an LCD display, to setup an array of strings. Because strings themselves are arrays, this is actually an example of a two-dimensional array.
|
||||
|
||||
These tend to be large structures so putting them into program memory is often desirable. The code below illustrates the idea.
|
||||
|
||||
.. code:: cpp
|
||||
|
||||
// Define Strings
|
||||
const char string_0[] PROGMEM = "String 0";
|
||||
const char string_1[] PROGMEM = "String 1";
|
||||
const char string_2[] PROGMEM = "String 2";
|
||||
const char string_3[] PROGMEM = "String 3";
|
||||
const char string_4[] PROGMEM = "String 4";
|
||||
const char string_5[] PROGMEM = "String 5";
|
||||
|
||||
// Initialize Table of Strings
|
||||
const char* const string_table[] PROGMEM = { string_0, string_1, string_2, string_3, string_4, string_5 };
|
||||
|
||||
char buffer[30]; // buffer for reading the string to (needs to be large enough to take the longest string
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.println("OK");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
for (int i = 0; i < 6; i++) {
|
||||
strcpy_P(buffer, (char*)pgm_read_dword(&(string_table[i])));
|
||||
Serial.println(buffer);
|
||||
delay(500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
In summary
|
||||
----------
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user