PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

eeprom_read.ino 1.5KB

3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * EEPROM Read
  3. *
  4. * Reads the value of each byte of the EEPROM and prints it
  5. * to the computer.
  6. * This example code is in the public domain.
  7. */
  8. #include <EEPROM.h>
  9. // start reading from the first byte (address 0) of the EEPROM
  10. unsigned int address = 0;
  11. byte value;
  12. void setup()
  13. {
  14. // initialize serial and wait for port to open:
  15. Serial.begin(9600);
  16. while (!Serial) {
  17. ; // wait for serial port to connect. Needed for Leonardo only
  18. }
  19. }
  20. void loop()
  21. {
  22. // read a byte from the current address of the EEPROM
  23. value = EEPROM.read(address);
  24. Serial.print(address);
  25. Serial.print("\t");
  26. Serial.print(value, DEC);
  27. Serial.println();
  28. /***
  29. Advance to the next address, when at the end restart at the beginning.
  30. Larger AVR processors have larger EEPROM sizes, E.g:
  31. - Arduno Duemilanove: 512b EEPROM storage.
  32. - Arduino Uno: 1kb EEPROM storage.
  33. - Arduino Mega: 4kb EEPROM storage.
  34. - Teensy 3.0 & 3.1: 2kb EEPROM storage.
  35. - Teensy-LC: 128b EEPROM storage.
  36. - Teensy 2.0: 1kb EEPROM storage.
  37. - Teensy++ 2.0: 4kb EEPROM storage.
  38. Rather than hard-coding the length, you should use the pre-provided length function.
  39. This will make your code portable to all AVR processors.
  40. ***/
  41. address = address + 1;
  42. if(address == EEPROM.length())
  43. address = 0;
  44. /***
  45. As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
  46. EEPROM address is also doable by a bitwise and of the length - 1.
  47. ++address &= EEPROM.length() - 1;
  48. ***/
  49. delay(500);
  50. }