/* * mata avispas – Flyback high voltage generator controller * ESP32‑C3 as Access Point + Web server to configure PWM driving an XY‑MOS driver * * PWM output: GPIO2 (adjustable via LEDC) * Web page: http://192.168.4.1 * AP SSID: MataAvispas_AP * AP Password: avispas123 * * The page lets you set: * - Frequency (Hz) : 100 – 20000 * - Duty cycle (%) : 0 – 100 * - Enable/Disable output * * Uses the ESP32 Arduino core (https://github.com/espressif/arduino-esp32) */ #include #include // ==== USER SETTINGS ==== const char* AP_SSID = "MataAvispas_AP"; const char* AP_PASSWORD = "avispas123"; const uint8_t PWM_GPIO = 2; // XY‑MOS INPUT pin const uint8_t PWM_CHANNEL = 0; // LEDC channel 0 const uint8_t PWM_RESOLUTION = 10; // 10‑bit resolution => 0‑1023 // ======================= WebServer server(80); // Current PWM state uint32_t pwmFrequency = 1000; // default 1 kHz uint32_t pwmDuty = 512; // 50 % of 1023 bool pwmEnabled = false; // HTML page (stored in PROGMEM to save RAM) const char INDEX_HTML[] PROGMEM = R"rawliteral( Mata Avispas – PWM Config

Mata Avispas

PWM: OFF
Range: 100 – 20000 Hz 50%
)rawliteral"; void handleRoot() { server.send_P(200, "text/html", INDEX_HTML, strlen_P(INDEX_HTML)); } void handleGet() { String json = "{"; json += "\"freq\":" + String(pwmFrequency) + ","; json += "\"duty\":" + String(map(pwmDuty, 0, (1<= 0) { String sub = body.substring(idx + 7); freq = sub.substring(0, sub.indexOf(",")).toInt(); } idx = body.indexOf("\"duty\":"); if (idx >= 0) { String sub = body.substring(idx + 7); duty = sub.substring(0, sub.indexOf(",")).toInt(); } idx = body.indexOf("\"en\":"); if (idx >= 0) { String sub = body.substring(idx + 5); en = sub.substring(0, sub.indexOf("}")).toInt(); } // Clamp values if (freq < 100) freq = 100; if (freq > 20000) freq = 20000; if (duty < 0) duty = 0; if (duty > 100) duty = 100; // Update PWM pwmFrequency = freq; pwmDuty = map(duty, 0, 100, 0, (1<