大家好,我是Arduino世界的新手,我在Arduino RAM中存储临时值时遇到问题,所以我想我会用PROGMEM将它们存储在闪存中。 我试图存储2字节数组但我不能让它们存储后显示。经过一些测试后,我不能让串行打印正常工作,但如果在同一时间,有人可以更好地解释PROGMEM将有所帮助。到目前为止我的代码是:
#include <avr/pgmspace.h>
struct GRID{
boolean isOn;
uint16_t color;
uint8_t X;
uint8_t Y;
};
GRID landed[10][22];
GRID falling[22][10];
//PROGMEM prog_uint8_t xAxis[] = {1,2,3,4,5,6,7,8,9,10};
//PROGMEM prog_uint8_t yAxis[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22};
uint8_t xAxis[] = {1,2,3,4,5,6,7,8,9,10};
uint8_t yAxis[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22};
void iniLanded(){
for(int i = 0; i < 10; i++)
for(int j = 0; j < 22; j++){
landed[i][j].color=0x0000;
landed[i][j].X = xAxis[i];
landed[i][j].Y = yAxis[j];
}
}
void iniFalling(){
for(int i = 0; i < 22; i++)
for(int j = 0; j < 10; j++){
falling[i][j].color=0x0000;
falling[i][j].X = xAxis[j];
falling[i][j].Y = yAxis[i];
}
}
void printLanded(){
for(int i = 0; i < 10; i++)
for(int j = 0; j < 22; j++){
Serial.print(landed[i][j].X); Serial.print(" "); Serial.println(landed[i][j].Y);
}
}
void printFalling(){
for(int i = 0; i < 22; i++)
for(int j = 0; j < 10; j++){
Serial.print(landed[i][j].X); Serial.print(" "); Serial.println(landed[i][j].Y);
}
}
void setup(){
Serial.begin(9600);
iniLanded();
iniFalling();
}
void loop(){
Serial.println(F("Hello World!"));
delay(100);
/*printLanded();
delay(100);
printFalling();
delay(100);*/
}
答案 0 :(得分:1)
诀窍在于你从flash调用的方式。请参阅我的示例this is where I define,就像您的评论代码一样。 这是您回拨数据的地方。注意使用pgm_read_word_near和deference&amp;。对于字节,单词等有其他类似函数found here ...