Risparmia memoria (PROGMEM).

Anche le "stringhe" nelle array di stringhe sono memorizzate nella RAM e la macro F() non può essere applicata ad esse. Cioè, il codice seguente porterà a un errore:
const char *names[] = { 
     F("Period"),  // 0 
     F("Work"),   // 1 
     F("Stop"),    // 2
};
Un array di stringhe può essere memorizzato in PROGMEM, memoria di programma del microcontrollore, Flash. Ecco una struttura che può essere utilizzata come modello:
// dichiarare "stringhe"
const char array_1[] PROGMEM = "Period";
const char array_2[] PROGMEM = "Work";
const char array_3[] PROGMEM = "Stop";
// dichiarare una tabella di puntatori
const char* const names[] PROGMEM = { 
     array_1, array_2, array_3,
}; 
void setup() 
     Serial.begin(9600); 
     char arrayBuf[10];  // creare un buffer
     // copia su arrayBuf usando strcpy_P integrato
     strcpy_P(arrayBuf, (char*)pgm_read_word(&(names[1]))); 
     Serial.println(arrayBuf);  // verrà visualizzato "Work"
}
Sì, è complicato e ingombrante, ma con una grande quantità di dati di testo, questo può salvare il progetto! Ad esempio, quando si crea un dispositivo con un menu di testo sul display. 
Crea il tuo sito web gratis! Questo sito è stato creato con Webnode. Crea il tuo sito gratuito oggi stesso! Inizia