Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: # EEPROM Persistence
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2026-01-23 11:16:16
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* perbaiki coding proyek THC_ESP32 saya agar bisa di */
- /* kontrol dan di monitor melalui web server */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- // EEPROM Management for THC Control Parameters
- // Handles reading/writing of THC parameters to persistent storage
- #include <EEPROM.h>
- // EEPROM Layout:
- // Program 1: Addresses 0-3 (SetV, DT, HyS, StV)
- // Program 2: Addresses 4-7 (SetV, DT, HyS, StV)
- // Program 3: Addresses 8-11 (SetV, DT, HyS, StV)
- // Current Program: Address 12 (Stores 1, 2, or 3)
- // ============================================================================
- // Default: Initialize EEPROM with factory default values
- // Sets up all three programs with identical default parameters
- // ============================================================================
- void Default(void) {
- // Default parameters for all programs:
- // SetV = 100V, DT = 0.5s, HyS = 8.0V, StV = 100V
- // Program 1 (EEPROM addresses 0-3)
- SetVa = 0;
- DTa = 1;
- HySa = 2;
- StVa = 3;
- SetV = 100; // Setpoint voltage: 100V
- DT = 5; // Delay time: 0.5s (stored as 5 = 5*0.1s)
- HyS = 80; // Hysteresis: 8.0V (stored as 80 = 80*0.1V)
- StV = 100; // Start voltage: 100V
- // Write Program 1 to EEPROM
- EEPROM.write(0, SetV);
- EEPROM.write(1, DT);
- EEPROM.write(2, HyS);
- EEPROM.write(3, StV);
- // Program 2 (EEPROM addresses 4-7)
- // Copy same values as Program 1
- EEPROM.write(4, SetV);
- EEPROM.write(5, DT);
- EEPROM.write(6, HyS);
- EEPROM.write(7, StV);
- // Program 3 (EEPROM addresses 8-11)
- // Copy same values as Program 1
- EEPROM.write(8, SetV);
- EEPROM.write(9, DT);
- EEPROM.write(10, HyS);
- EEPROM.write(11, StV);
- // Set current program to 1
- EEPROM.write(12, 1);
- // Commit changes to EEPROM
- EEPROM.commit();
- }
- // ============================================================================
- // ReadProg: Read currently selected program number from EEPROM
- // ============================================================================
- void ReadProg(void) {
- // Initialize EEPROM with size of 14 bytes
- EEPROM.begin(14);
- // Read program number from address 12
- program = EEPROM.read(12);
- }
- // ============================================================================
- // ReadDataProg_1: Load Program 1 parameters from EEPROM
- // Parameters stored at addresses: 0 (SetV), 1 (DT), 2 (HyS), 3 (StV)
- // ============================================================================
- void ReadDataProg_1(void) {
- for (int j = 0; j < ParamItem; j++) {
- Param[j] = EEPROM.read(j);
- }
- }
- // ============================================================================
- // ReadDataProg_2: Load Program 2 parameters from EEPROM
- // Parameters stored at addresses: 4 (SetV), 5 (DT), 6 (HyS), 7 (StV)
- // ============================================================================
- void ReadDataProg_2(void) {
- for (int j = 0; j < ParamItem; j++) {
- Param[j] = EEPROM.read(j + 4);
- }
- }
- // ============================================================================
- // ReadDataProg_3: Load Program 3 parameters from EEPROM
- // Parameters stored at addresses: 8 (SetV), 9 (DT), 10 (HyS), 11 (StV)
- // ============================================================================
- void ReadDataProg_3(void) {
- for (int j = 0; j < ParamItem; j++) {
- Param[j] = EEPROM.read(j + 8);
- }
- }
- // ============================================================================
- // SaveData: Write a parameter value to EEPROM
- // Parameters:
- // add (address): EEPROM address to write to
- // value: Value to store (typically 0-255 for byte values)
- // ============================================================================
- void SaveData(int add, int value) {
- // Write value to specified EEPROM address
- EEPROM.write(add, value);
- // Commit to persist the change immediately
- EEPROM.commit();
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment