I just started to work with PROGMEM and got to store strings, retrieve them and display everything on a LCD quite nice. However, soon as I try to display the same string twice the program stops at the point where i try to display the same value the second time.
It would be nice is you could have a look and maybe point me at a work around or to what I am missing. Since the whole sketch is quite long, I just post the important parts where the problem occurs.
#include <ShiftLCD.h>
#include <avr/pgmspace.h>
prog_char menu_0[] PROGMEM = "Sensitivity";
prog_char menu_1[] PROGMEM = "Room photo cut";
prog_char menu_2[] PROGMEM = "Room photo limit";
prog_char menu_3[] PROGMEM = "OS photo cut";
prog_char menu_4[] PROGMEM = "OS photo limit";
prog_char menu_5[] PROGMEM = "Room 1";
prog_char submenu_5_1[] PROGMEM = "R1 PIR delay";
prog_char submenu_5_2[] PROGMEM = "R1 HT1 Active";
prog_char submenu_5_3[] PROGMEM = "R1 Timer 1";
prog_char submenu_5_4[] PROGMEM = "R1 HT2 Active";
prog_char submenu_5_5[] PROGMEM = "R1 Timer 2";
prog_char submenu_5_6[] PROGMEM = "R1 HT3 Active";
prog_char submenu_5_7[] PROGMEM = "R1 Timer 3";
prog_char menu_6[] PROGMEM = "Room 2";
prog_char menu_7[] PROGMEM = "Room 3";
prog_char menu_8[] PROGMEM = "Room 4";
prog_char menu_9[] PROGMEM = "Room 5";
prog_char menu_10[] PROGMEM = "Room 6";
prog_char menu_11[] PROGMEM = "Room 7";
prog_char menu_12[] PROGMEM = "Room 8";
prog_char menu_13[] PROGMEM = "Room 9";
prog_char menu_14[] PROGMEM = "Room 10";
prog_char menu_15[] PROGMEM = "AC 1";
prog_char menu_16[] PROGMEM = "AC 2";
prog_char menu_17[] PROGMEM = "AC 3";
prog_char menu_18[] PROGMEM = "AC 4";
prog_char msg_0[] PROGMEM = "Not Used";
prog_char msg_1[] PROGMEM = "Saving....";
prog_char msg_2[] PROGMEM = "Setup mode";
prog_char msg_3[] PROGMEM = ">";
PROGMEM const char *menu_table[] = {
menu_0,
menu_1,
menu_2,
menu_3,
menu_4,
menu_5,
menu_6,
menu_7,
menu_8,
menu_9,
menu_10,
menu_11,
menu_12,
menu_13,
menu_14,
menu_15,
menu_16,
menu_17,
menu_18
};
PROGMEM const char *submenu_5_table[] = {
submenu_5_1,
submenu_5_2,
submenu_5_3,
submenu_5_4,
submenu_5_5,
submenu_5_6,
submenu_5_7
};
PROGMEM const char *msg_table[] = {
msg_0,
msg_1,
msg_2,
msg_3
};
That's the initializing and storing part of it. Next where I encounter the problem:
if(menuOption == 3){
lcd.clear();
lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(menu_table[2]))));
lcd.setCursor(0, 1);
lcd.print("NOT USED");
}
if(menuOption == 4){
lcd.clear();
lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(menu_table[3]))));
}
if(menuOption == 5){
lcd.clear();
lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(menu_table[4]))));
lcd.setCursor(0, 1);
lcd.print("NOT USED");
As you can see under menuOption 3 and menuOption 5 I have the lcd.print statement "lcd.print("NOT USED")".
If I replace 1 of this statements with "lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0]))));" it will work fine but soon as I try to read the message "NOT USED" the second time from the program memory everything freezes.
Any help would be kindly appreciated.
Thanks for having a look at.