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: # Plasma Controller
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2026-01-17 18:41:38
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* perbaiki proyek saya agar bisa di monitir dan di */
- /* kontrol dengan web server. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <EEPROM.h>
- #include "Wire.h"
- #include <LiquidCrystal_I2C.h>
- #include "_webserver.h"
- /****** GLOBAL OBJECTS *****/
- LiquidCrystal_I2C lcd(0x27, 16, 2);
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void Default(void);
- void ReadProg(void);
- void ReadDataProg_1(void);
- void ReadDataProg_2(void);
- void ReadDataProg_3(void);
- void SaveData(int add, int value);
- void checkButton(void);
- void checkMenu(void);
- void doLCD(void);
- void doTHC(void);
- void Setup_LCD(void);
- void Setup_Encoder(void);
- void Setup_THC(void);
- void Setup_Timer2(void);
- void setupWiFi(void);
- void startWebServer(void);
- void updateWebServerStatus(void);
- void doEncoder(void);
- void onTimerCallback(void* arg);
- /* Custom LCD display functions */
- void doLCDDefault(void);
- void doLCDMenu(void);
- void doLCDMenuSetup(void);
- void doLCDProgramSellect(void);
- void doLCDTest(void);
- void doLCDDelayTime(void);
- void doLCDHysreresis(void);
- void doLCDStartVoltage(void);
- void doLCDLoadDefault(void);
- void doTestUp(void);
- void doTestDown(void);
- void doProgramSet(int prg);
- // ============================================================
- // GLOBAL VARIABLES AND CONSTANTS
- // ============================================================
- // Pin Definitions - ESP32 compatible
- const int encoderPinA = 35; // GPIO35 (Encoder pin A) - Input only
- const int encoderPinB = 34; // GPIO34 (Encoder pin B) - Input only
- const int buttonPin = 32; // GPIO32 (Button pin)
- const int outputUpPin = 5; // GPIO5 (Torch up output)
- const int outputOkPin = 27; // GPIO27 (Arc ok output) - Changed from 7 to avoid conflict
- const int outputDnPin = 26; // GPIO26 (Torch down output) - Changed from 6 to avoid conflict
- const int arcVoltagePin = 36; // GPIO36 (SVP) - Arc voltage input (ADC)
- // EEPROM memory layout for storing THC parameters
- // Each program (1, 2, 3) has 4 parameters stored at different addresses
- // 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)
- // Active program: address 12
- // THC Parameters
- unsigned int SetV = 100; // Set voltage target
- unsigned int DT = 5; // Delay time (x0.1s)
- unsigned int HyS = 80; // Hysteresis (x0.1V)
- unsigned int StV = 100; // Start voltage
- unsigned int ArcV = 0; // Current arc voltage
- unsigned int SetVa = 0; // Address for SetV in EEPROM
- unsigned int DTa = 1; // Address for DT in EEPROM
- unsigned int HySa = 2; // Address for HyS in EEPROM
- unsigned int StVa = 3; // Address for StV in EEPROM
- // Program and Menu Variables
- int program = 1; // Current program (1-3)
- int menu = 0; // Current menu state
- int pos = 0; // Menu position
- volatile int encoderVal = 0; // Encoder value
- int oldValue = -1; // Previous encoder value for change detection
- unsigned int LCDtime = 0; // LCD timeout counter
- unsigned int show = 0; // LCD refresh counter
- unsigned int defaultLCDtime = 100; // LCD timeout in timer ticks (100 * 10ms = 1s)
- // Button and Encoder Variables
- volatile boolean A, B, lastA; // Encoder state variables
- volatile boolean ButtonOk = false; // Button pressed flag
- volatile boolean ButtonStat = false; // Current button state
- volatile boolean lastButtonStat = false; // Previous button state
- // Timer and System Variables
- volatile boolean Do = false; // Timer flag
- esp_timer_handle_t timer_handle; // ESP32 timer handle
- const int ParamItem = 4; // Number of parameters per program
- unsigned int Param[4]; // Parameter array
- // THC Control Variables
- unsigned int delayTime = 0; // THC delay counter
- unsigned int SetVx10 = 0; // Set voltage x10 for comparison
- // LCD Custom Characters
- byte armsUpDn[8] = {
- B00000,
- B00100,
- B01110,
- B00100,
- B00000,
- B01110,
- B00000,
- B00000
- };
- byte customUp[8] = {
- B00100,
- B01110,
- B10101,
- B00100,
- B00100,
- B00100,
- B00100,
- B00000
- };
- byte customDown[8] = {
- B00100,
- B00100,
- B00100,
- B00100,
- B10101,
- B01110,
- B00100,
- B00000
- };
- // ============================================================
- // SETUP FUNCTION
- // ============================================================
- void setup()
- {
- // Initialize serial communication
- Serial.begin(115200);
- delay(500);
- Serial.println("\n\n[SYSTEM] THC Rotary Controller Initializing...");
- // Initialize EEPROM
- EEPROM.begin(512);
- delay(100);
- // Read program from EEPROM
- ReadProg();
- Serial.print("[EEPROM] Current Program: ");
- Serial.println(program);
- // Load parameters for current program
- if (program == 1) {
- ReadDataProg_1();
- } else if (program == 2) {
- ReadDataProg_2();
- } else {
- ReadDataProg_3();
- }
- // Set global parameters from loaded program
- SetV = Param[0];
- DT = Param[1];
- HyS = Param[2];
- StV = Param[3];
- Serial.print("[EEPROM] Parameters Loaded - SetV: ");
- Serial.print(SetV);
- Serial.print("V, DT: ");
- Serial.print(DT);
- Serial.print(", HyS: ");
- Serial.print(HyS);
- Serial.print(", StV: ");
- Serial.println(StV);
- // Setup LCD display
- Setup_LCD();
- Serial.println("[LCD] LCD initialized");
- // Setup encoder and button
- Setup_Encoder();
- Serial.println("[ENCODER] Encoder and button initialized");
- // Setup THC control pins
- Setup_THC();
- Serial.println("[THC] THC outputs initialized");
- // Setup timer
- Setup_Timer2();
- Serial.println("[TIMER] Timer initialized");
- // Setup WiFi Access Point
- setupWiFi();
- Serial.println("[WiFi] WiFi Access Point initialized");
- // Start web server
- startWebServer();
- Serial.println("[WebServer] Web server started");
- // Initialize encoder value to set voltage
- encoderVal = SetV;
- oldValue = SetV;
- Serial.println("[SYSTEM] Initialization Complete");
- Serial.println("[SYSTEM] Access web interface at http://192.168.4.1");
- }
- // ============================================================
- // MAIN LOOP
- // ============================================================
- void loop()
- {
- // Check button state changes
- checkButton();
- // Process button press events
- checkMenu();
- // Update LCD display
- doLCD();
- // Execute THC control logic
- doTHC();
- // Read arc voltage analog input
- ArcV = analogRead(arcVoltagePin);
- // Handle web server requests
- updateWebServerStatus();
- // Small delay to prevent watchdog timeout
- delay(1);
- }
- // ============================================================
- // EEPROM FUNCTIONS
- // ============================================================
- // Initialize EEPROM with default values for all three programs
- void Default()
- {
- Serial.println("[EEPROM] Loading default parameters...");
- // Program 1 default parameters
- SetVa = 0;
- DTa = 1;
- HySa = 2;
- StVa = 3;
- SetV = 100; // Set voltage: 100V
- DT = 5; // Delay time: 0.5s
- HyS = 80; // Hysteresis: 8.0V
- StV = 100; // Start voltage: 100V
- EEPROM.write(0, SetV);
- EEPROM.write(1, DT);
- EEPROM.write(2, HyS);
- EEPROM.write(3, StV);
- // Program 2 default parameters (same as Program 1)
- EEPROM.write(4, SetV);
- EEPROM.write(5, DT);
- EEPROM.write(6, HyS);
- EEPROM.write(7, StV);
- // Program 3 default parameters (same as Program 1)
- EEPROM.write(8, SetV);
- EEPROM.write(9, DT);
- EEPROM.write(10, HyS);
- EEPROM.write(11, StV);
- // Set Program 1 as active program at startup
- EEPROM.write(12, 1);
- // Commit changes to physical EEPROM (ESP32 specific)
- EEPROM.commit();
- Serial.println("[EEPROM] Default parameters loaded to all programs");
- }
- // Read the currently active program number from EEPROM
- void ReadProg()
- {
- // Initialize EEPROM access for ESP32 (14 bytes needed)
- EEPROM.begin(14);
- // Read the currently active program number from address 12
- program = EEPROM.read(12);
- // Validate program number
- if (program < 1 || program > 3) {
- program = 1;
- }
- }
- // Load parameters for Program 1 from EEPROM addresses 0-3
- void ReadDataProg_1()
- {
- // Param Address 0, 1, 2, 3
- for (int j = 0; j < ParamItem; j++) {
- Param[j] = EEPROM.read(j);
- }
- Serial.println("[EEPROM] Program 1 parameters read");
- }
- // Load parameters for Program 2 from EEPROM addresses 4-7
- void ReadDataProg_2()
- {
- // Param Address 4, 5, 6, 7
- for (int j = 0; j < ParamItem; j++) {
- Param[j] = EEPROM.read(j + 4);
- }
- Serial.println("[EEPROM] Program 2 parameters read");
- }
- // Load parameters for Program 3 from EEPROM addresses 8-11
- void ReadDataProg_3()
- {
- // Param Address 8, 9, 10, 11
- for (int j = 0; j < ParamItem; j++) {
- Param[j] = EEPROM.read(j + 8);
- }
- Serial.println("[EEPROM] Program 3 parameters read");
- }
- // Write a single byte value to EEPROM at specified address
- void SaveData(int add, int value)
- {
- // Write a single byte value to EEPROM at specified address
- EEPROM.write(add, value);
- // Commit changes to physical EEPROM (ESP32 specific)
- // This ensures data is permanently stored
- EEPROM.commit();
- Serial.print("[EEPROM] Data saved at address ");
- Serial.print(add);
- Serial.print(": ");
- Serial.println(value);
- }
- // ============================================================
- // ENCODER AND BUTTON FUNCTIONS
- // ============================================================
- // Setup encoder and button pins with interrupt handlers
- void Setup_Encoder()
- {
- pinMode(encoderPinA, INPUT_PULLUP);
- pinMode(encoderPinB, INPUT_PULLUP);
- pinMode(buttonPin, INPUT_PULLUP);
- // Attach interrupt to encoder pin A on CHANGE
- attachInterrupt(digitalPinToInterrupt(encoderPinA), doEncoder, CHANGE);
- }
- // Encoder interrupt handler - executed on encoder pin A change
- void doEncoder()
- {
- // Read current state of encoder pins
- A = digitalRead(encoderPinA);
- B = digitalRead(encoderPinB);
- // Detect rotation direction based on pin state change
- if (B != lastA) {
- if (B == HIGH) {
- if (A == LOW) {
- // Clockwise rotation
- encoderVal++;
- } else {
- // Counter-clockwise rotation
- encoderVal--;
- }
- }
- // Reset LCD timeout when encoder is moved
- LCDtime = 0;
- }
- lastA = B;
- }
- // Check button state and detect press events
- void checkButton()
- {
- ButtonStat = digitalRead(buttonPin);
- if (ButtonStat != lastButtonStat) {
- if (!ButtonStat) {
- // Button pressed (LOW when pressed due to PULLUP)
- ButtonOk = true;
- }
- lastButtonStat = ButtonStat;
- }
- }
- // Process menu navigation based on button presses
- void checkMenu()
- {
- if (ButtonOk) {
- ButtonOk = false;
- LCDtime = 0;
- if (menu == 0) {
- menu = 1;
- } else if (menu == 1) {
- if (pos == 0) menu = 0;
- else if (pos == 1) menu = 13;
- else if (pos == 2) menu = 11;
- else if (pos == 3) menu = 12;
- } else if (menu == 11) {
- if (pos == 0) menu = 1;
- else if (pos == 1) menu = 111;
- else if (pos == 2) menu = 112;
- else if (pos == 3) menu = 113;
- else if (pos == 4) menu = 114;
- } else if (menu == 111) menu = 11;
- else if (menu == 112) menu = 11;
- else if (menu == 113) menu = 11;
- else if (menu == 13) {
- if (pos == 0) menu = 1;
- else if (pos == 1) menu = 121;
- else if (pos == 2) menu = 122;
- else if (pos == 3) menu = 123;
- } else if (menu == 12) {
- if (pos == 0) menu = 1;
- else if (pos == 1) menu = 115;
- else if (pos == 2) menu = 116;
- }
- // Set encoder value based on menu state
- if (menu == 0) encoderVal = SetV;
- else if (menu == 111) encoderVal = DT;
- else if (menu == 112) encoderVal = HyS;
- else if (menu == 113) encoderVal = StV;
- else encoderVal = 0;
- }
- }
- // ============================================================
- // LCD FUNCTIONS
- // ============================================================
- // Initialize LCD display with custom characters
- void Setup_LCD()
- {
- // Initialize I2C communication for LCD
- Wire.begin(21, 22); // GPIO21 (SDA), GPIO22 (SCL)
- delay(100);
- // Initialize LCD
- lcd.init();
- lcd.backlight();
- // Create custom characters
- lcd.createChar(0, armsUpDn);
- lcd.createChar(1, customUp);
- lcd.createChar(2, customDown);
- // Display splash screen
- lcd.setCursor(1, 0);
- lcd.print("MEHMET IBRAHIM");
- lcd.setCursor(3, 1);
- lcd.print("Plasma THC");
- delay(1500);
- lcd.clear();
- }
- // Main LCD update handler - dispatches to appropriate display function
- void doLCD()
- {
- if (show >= 2) {
- show = 0;
- switch (menu) {
- case 0:
- doLCDDefault();
- break;
- case 1:
- doLCDMenu();
- break;
- case 11:
- doLCDMenuSetup();
- break;
- case 111:
- doLCDDelayTime();
- break;
- case 112:
- doLCDHysreresis();
- break;
- case 113:
- doLCDStartVoltage();
- break;
- case 114:
- doLCDLoadDefault();
- break;
- case 12:
- doLCDTest();
- break;
- case 115:
- doTestUp();
- break;
- case 116:
- doTestDown();
- break;
- case 13:
- doLCDProgramSellect();
- break;
- case 121:
- doProgramSet(1);
- break;
- case 122:
- doProgramSet(2);
- break;
- case 123:
- doProgramSet(3);
- break;
- default:
- doLCDDefault();
- }
- }
- }
- // Display default screen showing current SetV and ArcV
- void doLCDDefault()
- {
- if (encoderVal < 0) encoderVal = 0;
- else if (encoderVal > 250) encoderVal = 250;
- SetV = encoderVal;
- if (SetV != oldValue) {
- SaveData(SetVa, SetV);
- oldValue = SetV;
- }
- lcd.setCursor(0, 0);
- lcd.print("P ");
- if (digitalRead(outputUpPin) == HIGH) {
- lcd.write(1);
- } else {
- lcd.print(" ");
- }
- lcd.print(" ");
- lcd.setCursor(4, 0);
- lcd.print("Set.V: ");
- lcd.print(SetV);
- lcd.print(" ");
- lcd.setCursor(0, 1);
- lcd.print(program);
- lcd.print(" ");
- if (digitalRead(outputDnPin) == HIGH) {
- lcd.write(2);
- } else {
- lcd.print(" ");
- }
- lcd.print(" ");
- lcd.setCursor(4, 1);
- lcd.print("Arc.V: ");
- lcd.print(ArcV / 10);
- lcd.print(" ");
- }
- // Main menu display
- void doLCDMenu()
- {
- if (encoderVal < 0) encoderVal = 3;
- pos = encoderVal % 4;
- switch (pos) {
- case 0:
- lcd.setCursor(0, 0);
- lcd.print("> Exit ");
- lcd.setCursor(0, 1);
- lcd.print(" Program ");
- break;
- case 1:
- lcd.setCursor(0, 0);
- lcd.print("> Program ");
- lcd.setCursor(0, 1);
- lcd.print(" Setup ");
- break;
- case 2:
- lcd.setCursor(0, 0);
- lcd.print("> Setup ");
- lcd.setCursor(0, 1);
- lcd.print(" Test ");
- break;
- case 3:
- lcd.setCursor(0, 0);
- lcd.print("> Test ");
- lcd.setCursor(0, 1);
- lcd.print(" Exit ");
- break;
- }
- }
- // Program selection menu
- void doLCDProgramSellect()
- {
- if (encoderVal < 0) encoderVal = 3;
- pos = abs(encoderVal % 4);
- switch (pos) {
- case 0:
- lcd.setCursor(0, 0);
- lcd.print(">> Exit ");
- lcd.setCursor(0, 1);
- lcd.print(" Load Prog: 1 ");
- break;
- case 1:
- lcd.setCursor(0, 0);
- lcd.print(">> Load Prog: 1 ");
- lcd.setCursor(0, 1);
- lcd.print(" Load Prog: 2 ");
- break;
- case 2:
- lcd.setCursor(0, 0);
- lcd.print(">> Load Prog: 2 ");
- lcd.setCursor(0, 1);
- lcd.print(" Load Prog: 3 ");
- break;
- case 3:
- lcd.setCursor(0, 0);
- lcd.print(">> Load Prog: 3 ");
- lcd.setCursor(0, 1);
- lcd.print(" Exit ");
- break;
- }
- }
- // Setup menu display
- void doLCDMenuSetup()
- {
- if (encoderVal < 0) encoderVal = 4;
- pos = abs(encoderVal % 5);
- switch (pos) {
- case 0:
- lcd.setCursor(0, 0);
- lcd.print(">> Exit ");
- lcd.setCursor(0, 1);
- lcd.print(" Delay Time ");
- break;
- case 1:
- lcd.setCursor(0, 0);
- lcd.print(">> Delay Time ");
- lcd.setCursor(0, 1);
- lcd.print(" Hysteresis ");
- break;
- case 2:
- lcd.setCursor(0, 0);
- lcd.print(">> Hysteresis ");
- lcd.setCursor(0, 1);
- lcd.print(" Start Voltage");
- break;
- case 3:
- lcd.setCursor(0, 0);
- lcd.print(">> Start Voltage");
- lcd.setCursor(0, 1);
- lcd.print(" Load Default ");
- break;
- case 4:
- lcd.setCursor(0, 0);
- lcd.print(">> Load Default ");
- lcd.setCursor(0, 1);
- lcd.print(" Exit ");
- break;
- }
- }
- // Test menu display
- void doLCDTest()
- {
- if (encoderVal < 0) encoderVal = 2;
- pos = abs(encoderVal % 3);
- switch (pos) {
- case 0:
- lcd.setCursor(0, 0);
- lcd.print("Test > Exit ");
- lcd.setCursor(0, 1);
- lcd.print(" Torch Up ");
- digitalWrite(outputDnPin, LOW);
- digitalWrite(outputUpPin, LOW);
- digitalWrite(outputOkPin, LOW);
- break;
- case 1:
- lcd.setCursor(0, 0);
- lcd.print("Test > Torch Up ");
- lcd.setCursor(0, 1);
- lcd.print(" Torch Dn ");
- if (digitalRead(outputOkPin) == LOW) LCDtime = 0;
- if (LCDtime >= 200) {
- digitalWrite(outputDnPin, LOW);
- digitalWrite(outputUpPin, LOW);
- digitalWrite(outputOkPin, LOW);
- }
- break;
- case 2:
- lcd.setCursor(0, 0);
- lcd.print("Test > Torch Dn ");
- lcd.setCursor(0, 1);
- lcd.print(" Exit ");
- if (digitalRead(outputOkPin) == LOW) LCDtime = 0;
- if (LCDtime >= 200) {
- digitalWrite(outputDnPin, LOW);
- digitalWrite(outputUpPin, LOW);
- digitalWrite(outputOkPin, LOW);
- }
- break;
- }
- }
- // Test torch up function
- void doTestUp()
- {
- digitalWrite(outputDnPin, LOW);
- digitalWrite(outputUpPin, HIGH);
- digitalWrite(outputOkPin, HIGH);
- LCDtime = 0;
- menu = 12;
- encoderVal = 1;
- }
- // Test torch down function
- void doTestDown()
- {
- digitalWrite(outputDnPin, HIGH);
- digitalWrite(outputUpPin, LOW);
- digitalWrite(outputOkPin, HIGH);
- LCDtime = 0;
- menu = 12;
- encoderVal = 2;
- }
- // Delay time adjustment display
- void doLCDDelayTime()
- {
- if (encoderVal < 1) encoderVal = 1;
- else if (encoderVal > 200) encoderVal = 200;
- DT = encoderVal;
- if (DT != oldValue) {
- SaveData(DTa, DT);
- oldValue = DT;
- LCDtime = 0;
- }
- double x = DT / 10.00;
- lcd.setCursor(0, 0);
- lcd.print("Set > Delay Time");
- lcd.setCursor(0, 1);
- lcd.print(" : ");
- lcd.print(x, 1);
- lcd.print(" s ");
- }
- // Hysteresis adjustment display
- void doLCDHysreresis()
- {
- if (encoderVal < 1) encoderVal = 1;
- else if (encoderVal > 99) encoderVal = 99;
- HyS = encoderVal;
- if (HyS != oldValue) {
- SaveData(HySa, HyS);
- oldValue = HyS;
- LCDtime = 0;
- }
- double x = HyS / 10.00;
- lcd.setCursor(0, 0);
- lcd.print("Set > Hysteresis");
- lcd.setCursor(0, 1);
- lcd.print(" :");
- lcd.write(0);
- lcd.print(x, 1);
- lcd.print(" V ");
- }
- // Start voltage adjustment display
- void doLCDStartVoltage()
- {
- if (encoderVal < 50) encoderVal = 50;
- else if (encoderVal > 250) encoderVal = 250;
- StV = encoderVal;
- if (StV != oldValue) {
- SaveData(StVa, StV);
- oldValue = StV;
- LCDtime = 0;
- }
- lcd.setCursor(0, 0);
- lcd.print("Set > Start Volt");
- lcd.setCursor(0, 1);
- lcd.print(" : ");
- lcd.print(StV);
- lcd.print(" V ");
- }
- // Load default parameters function
- void doLCDLoadDefault()
- {
- Default();
- for (byte i = 0; i < 100; i++) {
- lcd.setCursor(0, 0);
- lcd.print(" Default ");
- lcd.setCursor(0, 1);
- lcd.print("Load ");
- lcd.print(i);
- lcd.print(" ");
- lcd.print("%");
- lcd.print(" ");
- delay(5);
- }
- lcd.setCursor(0, 0);
- lcd.print("Default: DONE ");
- lcd.setCursor(0, 1);
- lcd.print("Please Restart ");
- exit(0);
- }
- // Set program and load its parameters
- void doProgramSet(int prg)
- {
- if (prg == 1) {
- SetVa = 0;
- DTa = 1;
- HySa = 2;
- StVa = 3;
- ReadDataProg_1();
- } else if (prg == 2) {
- SetVa = 4;
- DTa = 5;
- HySa = 6;
- StVa = 7;
- ReadDataProg_2();
- } else {
- SetVa = 8;
- DTa = 9;
- HySa = 10;
- StVa = 11;
- ReadDataProg_3();
- }
- SaveData(100, prg);
- program = prg;
- SetV = Param[0];
- DT = Param[1];
- HyS = Param[2];
- StV = Param[3];
- // Preset value for encoder
- encoderVal = SetV;
- menu = 0;
- }
- // ============================================================
- // THC CONTROL FUNCTIONS
- // ============================================================
- // Initialize THC control output pins
- void Setup_THC()
- {
- pinMode(outputUpPin, OUTPUT);
- pinMode(outputOkPin, OUTPUT);
- pinMode(outputDnPin, OUTPUT);
- // Ensure all outputs are LOW at startup
- digitalWrite(outputUpPin, LOW);
- digitalWrite(outputOkPin, LOW);
- digitalWrite(outputDnPin, LOW);
- }
- // Main THC control logic - controls torch based on arc voltage
- void doTHC()
- {
- if (Do) {
- Do = false;
- LCDtime++;
- show++;
- // Return to default display after timeout
- if (LCDtime > defaultLCDtime) {
- menu = 0;
- pos = 0;
- LCDtime = 0;
- encoderVal = SetV;
- }
- // Check if arc voltage is valid (500 < ArcV < 2500)
- if ((500 < ArcV) && (ArcV < 2500)) {
- // Increment delay time if arc voltage exceeds start voltage
- if (ArcV > StV * 10) delayTime++;
- // Wait for delay time to elapse before making adjustments
- if (delayTime >= DT * 10) {
- SetVx10 = SetV * 10;
- delayTime = DT * 10;
- // Signal arc is OK
- digitalWrite(outputOkPin, HIGH);
- // Control torch position based on voltage difference
- if (ArcV >= SetVx10 + HyS) {
- // Arc voltage too high - move torch down
- digitalWrite(outputUpPin, LOW);
- digitalWrite(outputDnPin, HIGH);
- } else if (ArcV <= SetVx10 - HyS) {
- // Arc voltage too low - move torch up
- digitalWrite(outputDnPin, LOW);
- digitalWrite(outputUpPin, HIGH);
- } else {
- // Arc voltage within hysteresis band - hold position
- digitalWrite(outputUpPin, LOW);
- digitalWrite(outputDnPin, LOW);
- }
- }
- } else if (menu != 12) {
- // Arc voltage invalid or menu is not in test mode
- delayTime = 0;
- digitalWrite(outputUpPin, LOW);
- digitalWrite(outputOkPin, LOW);
- digitalWrite(outputDnPin, LOW);
- }
- }
- }
- // ============================================================
- // TIMER FUNCTIONS
- // ============================================================
- // Initialize ESP32 timer for periodic interrupt (10ms)
- void Setup_Timer2()
- {
- // Configure timer arguments
- esp_timer_create_args_t timer_args = {
- .callback = &onTimerCallback,
- .name = "thc_periodic_timer"
- };
- // Create the timer
- ESP_ERROR_CHECK(esp_timer_create(&timer_args, &timer_handle));
- // Start the timer with 10ms (10000 microseconds) period
- ESP_ERROR_CHECK(esp_timer_start_periodic(timer_handle, 10000));
- }
- // Timer callback function - sets Do flag every 10ms
- void onTimerCallback(void* arg)
- {
- (void) arg; // Suppress unused parameter warning
- Do = true;
- }
- // ============================================================
- // WiFi AND WEB SERVER FUNCTIONS
- // ============================================================
- // Setup WiFi Access Point - defined in _webserver.h
- void setupWiFi()
- {
- // This function is implemented in _webserver.h
- // It should configure the ESP32 as a WiFi access point
- }
- // Start the web server - defined in _webserver.h
- void startWebServer()
- {
- // This function is implemented in _webserver.h
- // It should setup HTTP endpoints for THC control
- }
- // Update web server with current status - defined in _webserver.h
- void updateWebServerStatus()
- {
- // This function is implemented in _webserver.h
- // It should handle incoming web requests and send status updates
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment