我有一个我想要制作的程序,它会询问变量是否已经存在.如果是,则显示它,如果没有,则显示它并使用PROGMEM命令将其存储在Arduino中.有人可以解释更多关于PROGMEM以及如何制作我正在谈论的程序吗?
一般来说,如果要在函数中创建任何变量,只有在函数关闭时才会存在,所有变量都将被删除.如果你想让它们保持活着,试着创建全局变量或在它之前使用static; 像这儿
static int myvariable;
Run Code Online (Sandbox Code Playgroud)
这是你的问题的答案
if (myvariable!=NULL)
{
printfucntion(myvariable);
}
Run Code Online (Sandbox Code Playgroud)
eeprom的解决方案
EEPROM读取读取EEPROM的每个字节的值并将其打印到计算机.
#include <EEPROM.h>
// start reading from the first byte (address 0) of the EEPROM
int address = 0;
byte value;
void setup()
{
Serial.begin(9600);
}
void loop()
{
// read a byte from the current address of the EEPROM
value = EEPROM.read(address);
Serial.print(address);
Serial.print("\t");
Serial.print(value, DEC);
Serial.println();
//move to next address of the EEPROM
address = address + 1;
// there are only 512 bytes of EEPROM, from 0 to 511, so if you are
// on address 512, wrap around to address 0
// if you have arduinoMega probably there is more eeprom space
if (address == 512)
address = 0;
delay(500);
}
Run Code Online (Sandbox Code Playgroud)
我希望我帮忙.