Flash
I have written a new library, Flash, which abstracts away most of the complexity of PROGMEM. It provides String, Array, and Table types that make ROM-based data collections as easy to use as “normal” types. Each overrides the C++ operator, so to get at individual elements, one simply uses familiar array syntax. For example, if you have 1000 floating point temperatures in a flash-based “temperature_table” array, you might write code like this:
for (int i=0; i<temperature_table.count(); ++i)
if (temperature_table[i] > 98.6)
Serial.println(temperature_table[i]);
Font tables are a good application for Flash. Assuming that font_table is a 256x7 table of On/Off values, one row for each character, this simple example displays the number “2” on a 7-segment display:
int digit = '2';
for (int i=0; i<7; ++i)
digitalWrite(pin[i], font_table[digit][i]);
Inline ROM Strings
One of the most useful features of Flash is the ability to use “inline”, or unnamed ROM-based strings. This provides a tremendous convenience for applications that process lots of string data. To print an inline flash string, you use the library’s built-in F() macro:
Serial << F("A very long ROM-based string?.");
For those uncomfortable with the << streaming notation, you can also write
Serial.print(F("A very long ROM-based string?"));
but this requires a minor patch to core file Print.h to tell it about Flash objects. (See the file patching_print.txt.)
I welcome feedback and suggestions for improvement. The library is posted here.
Thanks,
Mikal