diff options
author | Chris--A <chris@genx.biz> | 2015-03-20 12:06:20 +1000 |
---|---|---|
committer | Chris--A <chris@genx.biz> | 2015-03-20 12:06:20 +1000 |
commit | 26577474efcb8874dad687467a8ba2f01678ff4c (patch) | |
tree | 4eb3a3a9dc0e6e8b8a264676be14b1f0aa362070 /libraries/EEPROM/examples/eeprom_update/eeprom_update.ino | |
parent | fd4323f360885725c736c90745ee57dbca20e8a0 (diff) |
Updated EEPROM examples.
Removed hard coded lengths, which were incorrect for standard Arduino's
now.
Diffstat (limited to 'libraries/EEPROM/examples/eeprom_update/eeprom_update.ino')
-rw-r--r-- | libraries/EEPROM/examples/eeprom_update/eeprom_update.ino | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino b/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino index e0e18d8..dbf05ec 100644 --- a/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino +++ b/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino @@ -38,15 +38,32 @@ void loop() The function EEPROM.update(addr, val) is equivalent to the following: if( EEPROM.read(addr) != val ){ - EEPROM.write(addr, val); + EEPROM.write(addr, val); } ***/ - /** advance to the next address. there are 512 bytes in the EEPROM, so go back to 0 when we hit 512. **/ + /*** + Advance to the next address, when at the end restart at the beginning. + + Larger AVR processors have larger EEPROM sizes, E.g: + - Arduno Duemilanove: 512b EEPROM storage. + - Arduino Uno: 1kb EEPROM storage. + - Arduino Mega: 4kb EEPROM storage. + + Rather than hard-coding the length, you should use the pre-provided length function. + This will make your code portable to all AVR processors. + ***/ addr = addr + 1; - if (addr == 512) + if(addr == EEPROM.length()) addr = 0; + + /*** + As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an + EEPROM address is also doable by a bitwise and of the length - 1. + + ++addr &= EEPROM.length() - 1; + ***/ delay(100); } |