Since I am still not that comfortable using macros I could use some assistance here.
I want to move single dimension array of doubles ( sine wave) to program memory using flash.
So far I understand that various type #defined macros do that.
I do not quite get if I have to have the data predefined as used in sample ( attached) or can I just build the array, as I do now, and store it in program memory as I build it (naturally prefered to save RAM) or probably after .
Basically - how is the "value" build.
Thanks for helping.
Cheers Vaclav
Here are some snippets from samples how to use flash.
// Use these macros to define your flash-based data structures
// Example: FLASH_STRING(str, "Four score and seven years ago");
#define FLASH_STRING(name, value) \
static const char name##_flash[] PROGMEM = value; \
_FLASH_STRING name(name##_flash);
// Example: FLASH_ARRAY(float, temperatures, 98.1, 98.5, 99.1, 102.1);
#define FLASH_ARRAY(type, name, values...) \
static const type name##_flash[] PROGMEM = { values }; \
_FLASH_ARRAY<type> name(name##_flash, sizeof(name##_flash) / sizeof(type));
// Example: FLASH_TABLE(uint8_t, fonts, 7, {ON, OFF, ON, ON, OFF, ON, OFF}, {OFF, ON, OFF, ON, OFF, ON, OFF});
#define FLASH_TABLE(type, name, cols, values...) \
static const type name##_flash[][cols] PROGMEM = { values }; \
_FLASH_TABLE<type> name((const PROGMEM type *)name##_flash, sizeof(name##_flash) / sizeof(name##_flash[0]), cols);
// Example: FLASH_STRING_ARRAY(nums, PSTR("One"), PSTR("Two"), PSTR("Three"), PSTR("Four"), PSTR("Five"));
#define FLASH_STRING_ARRAY(name, values...) \
const PROGMEM char *name##_arr[] = { values }; \ why is PROGMEM used here ONLY ??
_FLASH_STRING_ARRAY name(name##_arr, sizeof(name##_arr) / sizeof(name##_arr[0]));
// Example: FLASH_ARRAY(float, temperatures, 98.1, 98.5, 99.1, 102.1);
#define FLASH_ARRAY(type, name, values...) \
static const type name##_flash[] PROGMEM = { values }; \
_FLASH_ARRAY<type> name(name##_flash, sizeof(name##_flash) / sizeof(type));
// // Example 3: Flash arrays
FLASH_ARRAY(int, sine_table,
0,6,12,18,25,31,37,43,49,56,62,68,74,80,86,92,97,103,109,115,120,126,131,136,142,
147,152,157,162,167,171,176,181,185,189,193,197,201,205,209,212,216,219,222,225,
228,231,234,236,238,241,243,244,246,248,249,251,252,253,254,254,255,255,255,256,
255,255,255,254,254,253,252,251,249,248,246,244,243,241,238,236,234,231,228,225,
222,219,216,212,209,205,201,197,193,189,185,181,176,171,167,162,157,152,147,142,
136,131,126,120,115,109,103,97,92,86,80,74,68,62,56,49,43,37,31,25,18,12,6,0,-6,
-12,-18,-25,-31,-37,-43,-49,-56,-62,-68,-74,-80,-86,-92,-97,-103,-109,-115,-120,
-126,-131,-136,-142,-147,-152,-157,-162,-167,-171,-176,-181,-185,-189,-193,-197,
-201,-205,-209,-212,-216,-219,-222,-225,-228,-231,-234,-236,-238,-241,-243,-244,
-246,-248,-249,-251,-252,-253,-254,-254,-255,-255,-255,-256,-255,-255,-255,-254,
-254,-253,-252,-251,-249,-248,-246,-244,-243,-241,-238,-236,-234,-231,-228,-225,
-222,-219,-216,-212,-209,-205,-201,-197,-193,-189,-185,-181,-176,-171,-167,-162,
-157,-152,-147,-142,-136,-131,-126,-120,-115,-109,-103,-97,-92,-86,-80,-74,-68,
-62,-56,-49,-43,-37,-31,-25,-18,-12,-6,-6,-12,-18,-25,-31,-37,-43,-49,-56,-62,
-68,-74,-80,-86,-92,-97,-103,-109,-115,-120,-126,-131,-136,-142,-147,-152,-157,
-162,-167,-171,-176,-181,-185,-189,-193,-197,-201,-205,-209,-212,-216,-219,-222,
-225,-228,-231,-234,-236,-238,-241,-243,-244,-246,-248,-249,-251,-252,-253,-254,
-254,-255,-255,-255,-256,-255,-255,-255,-254,-254,-253,-252,-251,-249,-248,-246,
-244,-243,-241,-238,-236,-234,-231,-228,-225,-222,-219,-216,-212,-209,-205,-201,
-197,-193,-189,-185,-181,-176,-171,-167,-162,-157,-152,-147,-142,-136,-131,-126,
-120,-115,-109,-103,-97,-92,-86,-80,-74,-68,-62,-56,-49,-43,-37,-31,-25,-18,-12,-6);
int iSize = availableMemory();
Serial.printf("Avaiable memory %i ", iSize);
// 3.a Print out the array
Serial.println("Table: "); sine_table.print(Serial); Serial.println();
for(;;);
// 3.b Determine the size of the array
Serial.print("Count: "); Serial.println(sine_table.count());
Serial.print("RAM: "); Serial.println(sizeof(sine_table));
// 3.c Access individual elements of the array using [] notation
int maximum = -1000;
for (int i=0; i<sine_table.count(); ++i)
if (sine_table[i] > maximum)
maximum = sine_table[i];
Serial.print("Peak: "); Serial.println(maximum);
moderator: changed quote to code tags ==> # button above smiley's