![](/img/trans.png)
[英]How do i store a byte array in Arduino flash memory using PROGMEM?
[英]An array of strings stored in flash with PROGMEM in Arduino
我正在使用AVR-GCC版本4.7.0,当我尝试在FLASH内存中创建一个字符串数组时,我得到错误:
变量'menu'必须是const才能通过' attribute ((progmem))'进入只读部分
我正在使用此代码:
const char menu0[] PROGMEM = "choice0";
const char menu1[] PROGMEM = "choice1";
const char menu2[] PROGMEM = "choice2";
const char menu3[] PROGMEM = "choice3";
const char menu4[] PROGMEM = "choice4";
const char menu5[] PROGMEM = "choice5";
const char *menu[] PROGMEM = {menu0, menu1, menu2, menu3, menu4, menu5};
我已经阅读了Stack Overflow问题C - 如何使用PROGMEM来存储和读取char数组 ,但我看到的所有答案都没有包含const
关键字,这让我相信它们是在需要之前编写的。
如何解决这个问题?
const char * const menu[] PROGMEM = {menu0, menu1, menu2, menu3, menu4, menu5};
是答案。
尝试
const char* const menu[] PROGMEM...
因此,数组本身是常量,而不是const char*
指针的可变数组,就像在原始代码中一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.