pleasedontcode

# EEPROM Persistence rev_02

Jan 23rd, 2026
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: # EEPROM Persistence
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2026-01-23 11:16:16
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* perbaiki coding proyek THC_ESP32 saya agar bisa di */
  21.     /* kontrol dan di monitor  melalui web server */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24.  
  25. /* START CODE */
  26.  
  27. // EEPROM Management for THC Control Parameters
  28. // Handles reading/writing of THC parameters to persistent storage
  29.  
  30. #include <EEPROM.h>
  31.  
  32. // EEPROM Layout:
  33. // Program 1: Addresses 0-3   (SetV, DT, HyS, StV)
  34. // Program 2: Addresses 4-7   (SetV, DT, HyS, StV)
  35. // Program 3: Addresses 8-11  (SetV, DT, HyS, StV)
  36. // Current Program: Address 12 (Stores 1, 2, or 3)
  37.  
  38. // ============================================================================
  39. // Default: Initialize EEPROM with factory default values
  40. // Sets up all three programs with identical default parameters
  41. // ============================================================================
  42. void Default(void) {
  43.   // Default parameters for all programs:
  44.   // SetV = 100V, DT = 0.5s, HyS = 8.0V, StV = 100V
  45.  
  46.   // Program 1 (EEPROM addresses 0-3)
  47.   SetVa = 0;
  48.   DTa = 1;
  49.   HySa = 2;
  50.   StVa = 3;
  51.  
  52.   SetV = 100;  // Setpoint voltage: 100V
  53.   DT = 5;      // Delay time: 0.5s (stored as 5 = 5*0.1s)
  54.   HyS = 80;    // Hysteresis: 8.0V (stored as 80 = 80*0.1V)
  55.   StV = 100;   // Start voltage: 100V
  56.  
  57.   // Write Program 1 to EEPROM
  58.   EEPROM.write(0, SetV);
  59.   EEPROM.write(1, DT);
  60.   EEPROM.write(2, HyS);
  61.   EEPROM.write(3, StV);
  62.  
  63.   // Program 2 (EEPROM addresses 4-7)
  64.   // Copy same values as Program 1
  65.   EEPROM.write(4, SetV);
  66.   EEPROM.write(5, DT);
  67.   EEPROM.write(6, HyS);
  68.   EEPROM.write(7, StV);
  69.  
  70.   // Program 3 (EEPROM addresses 8-11)
  71.   // Copy same values as Program 1
  72.   EEPROM.write(8, SetV);
  73.   EEPROM.write(9, DT);
  74.   EEPROM.write(10, HyS);
  75.   EEPROM.write(11, StV);
  76.  
  77.   // Set current program to 1
  78.   EEPROM.write(12, 1);
  79.  
  80.   // Commit changes to EEPROM
  81.   EEPROM.commit();
  82. }
  83.  
  84. // ============================================================================
  85. // ReadProg: Read currently selected program number from EEPROM
  86. // ============================================================================
  87. void ReadProg(void) {
  88.   // Initialize EEPROM with size of 14 bytes
  89.   EEPROM.begin(14);
  90.  
  91.   // Read program number from address 12
  92.   program = EEPROM.read(12);
  93. }
  94.  
  95. // ============================================================================
  96. // ReadDataProg_1: Load Program 1 parameters from EEPROM
  97. // Parameters stored at addresses: 0 (SetV), 1 (DT), 2 (HyS), 3 (StV)
  98. // ============================================================================
  99. void ReadDataProg_1(void) {
  100.   for (int j = 0; j < ParamItem; j++) {
  101.     Param[j] = EEPROM.read(j);
  102.   }
  103. }
  104.  
  105. // ============================================================================
  106. // ReadDataProg_2: Load Program 2 parameters from EEPROM
  107. // Parameters stored at addresses: 4 (SetV), 5 (DT), 6 (HyS), 7 (StV)
  108. // ============================================================================
  109. void ReadDataProg_2(void) {
  110.   for (int j = 0; j < ParamItem; j++) {
  111.     Param[j] = EEPROM.read(j + 4);
  112.   }
  113. }
  114.  
  115. // ============================================================================
  116. // ReadDataProg_3: Load Program 3 parameters from EEPROM
  117. // Parameters stored at addresses: 8 (SetV), 9 (DT), 10 (HyS), 11 (StV)
  118. // ============================================================================
  119. void ReadDataProg_3(void) {
  120.   for (int j = 0; j < ParamItem; j++) {
  121.     Param[j] = EEPROM.read(j + 8);
  122.   }
  123. }
  124.  
  125. // ============================================================================
  126. // SaveData: Write a parameter value to EEPROM
  127. // Parameters:
  128. //   add (address): EEPROM address to write to
  129. //   value: Value to store (typically 0-255 for byte values)
  130. // ============================================================================
  131. void SaveData(int add, int value) {
  132.   // Write value to specified EEPROM address
  133.   EEPROM.write(add, value);
  134.  
  135.   // Commit to persist the change immediately
  136.   EEPROM.commit();
  137. }
  138.  
  139. /* END CODE */
  140.  
Advertisement
Add Comment
Please, Sign In to add comment