PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

63 lines
1.6KB

  1. /*
  2. * EEPROM Write
  3. *
  4. * Stores values read from analog input 0 into the EEPROM.
  5. * These values will stay in the EEPROM when the board is
  6. * turned off and may be retrieved later by another sketch.
  7. */
  8. #include <EEPROM.h>
  9. /** the current address in the EEPROM (i.e. which byte we're going to write to next) **/
  10. unsigned int addr = 0;
  11. void setup(){ /** Empty setup. **/}
  12. void loop()
  13. {
  14. /***
  15. Need to divide by 4 because analog inputs range from
  16. 0 to 1023 and each byte of the EEPROM can only hold a
  17. value from 0 to 255.
  18. ***/
  19. int val = analogRead(0) / 4;
  20. /***
  21. Write the value to the appropriate byte of the EEPROM.
  22. these values will remain there when the board is
  23. turned off.
  24. ***/
  25. EEPROM.write(addr, val);
  26. /***
  27. Advance to the next address, when at the end restart at the beginning.
  28. Larger AVR processors have larger EEPROM sizes, E.g:
  29. - Arduno Duemilanove: 512b EEPROM storage.
  30. - Arduino Uno: 1kb EEPROM storage.
  31. - Arduino Mega: 4kb EEPROM storage.
  32. - Teensy 3.0 & 3.1: 2kb EEPROM storage.
  33. - Teensy-LC: 128b EEPROM storage.
  34. - Teensy 2.0: 1kb EEPROM storage.
  35. - Teensy++ 2.0: 4kb EEPROM storage.
  36. Rather than hard-coding the length, you should use the pre-provided length function.
  37. This will make your code portable to all AVR processors.
  38. ***/
  39. addr = addr + 1;
  40. if(addr == EEPROM.length())
  41. addr = 0;
  42. /***
  43. As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
  44. EEPROM address is also doable by a bitwise and of the length - 1.
  45. ++addr &= EEPROM.length() - 1;
  46. ***/
  47. delay(100);
  48. }