PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

57 lines
1.3KB

  1. /***
  2. eeprom_put example.
  3. This shows how to use the EEPROM.put() method.
  4. Also, this sketch will pre-set the EEPROM data for the
  5. example sketch eeprom_get.
  6. Note, unlike the single byte version EEPROM.write(),
  7. the put method will use update semantics. As in a byte
  8. will only be written to the EEPROM if the data is actually
  9. different.
  10. Written by Christopher Andrews 2015
  11. Released under MIT licence.
  12. ***/
  13. #include <EEPROM.h>
  14. struct MyObject{
  15. float field1;
  16. byte field2;
  17. char name[10];
  18. };
  19. void setup(){
  20. Serial.begin(9600);
  21. while (!Serial) {
  22. ; // wait for serial port to connect. Needed for Leonardo only
  23. }
  24. float f = 123.456f; //Variable to store in EEPROM.
  25. unsigned int eeAddress = 0; //Location we want the data to be put.
  26. //One simple call, with the address first and the object second.
  27. EEPROM.put( eeAddress, f );
  28. Serial.println("Written float data type!");
  29. /** Put is designed for use with custom structures also. **/
  30. //Data to store.
  31. MyObject customVar = {
  32. 3.14f,
  33. 65,
  34. "Working!"
  35. };
  36. eeAddress += sizeof(float); //Move address to the next byte after float 'f'.
  37. EEPROM.put( eeAddress, customVar );
  38. Serial.print( "Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!" );
  39. }
  40. void loop(){ /* Empty loop */ }