|
前几天偶然试了下IDE里自带的EEPROM READ例子,发现个有趣的事情:arduino运行例子后,每次打开IDE的串口监视窗,都会发现EEPROM的地址从0跑起。看了半天代码也没搞明白这是怎么做到的,请各位指点指点。谢谢 - #include <EEPROM.h>
- // start reading from the first byte (address 0) of the EEPROM
- int address = 0;
- byte value;
- void setup()
- {
- // initialize serial and wait for port to open:
- Serial.begin(9600);
- while (!Serial) {
- ; // wait for serial port to connect. Needed for Leonardo only
- }
- }
- 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();
-
- // advance to the next address of the EEPROM
- address = address + 1;
-
- // there are only 512 bytes of EEPROM, from 0 to 511, so if we're
- // on address 512, wrap around to address 0
- if (address == 512)
- address = 0;
-
- delay(500);
- }
复制代码 |
|