// ============================================================ // INTERMISSION OBJECT — MOTOR + HALL SENSOR TEST // // Motor cycles: 2 s ON → 1 s OFF → repeat. // No PWM — direct GPIO drive to rule out frequency/switching issues. // LED flashes on every Hall pulse (purely visual, no serial needed). // OTA stays active for wireless re-upload. // ============================================================ #include "wifi_ota.h" // ── Pins ───────────────────────────────────────────────────── #define PIN_LED_PWM 4 #define PIN_MOTOR 7 #define PIN_HALL 8 // ── PWM (LED only) ─────────────────────────────────────────── #define PWM_FREQ_LED 24989 #define PWM_RES 8 // ── Timing ─────────────────────────────────────────────────── #define MOTOR_ON_MS 2000UL // motor on duration #define MOTOR_OFF_MS 1000UL // motor off duration (cooling gap) #define DEBOUNCE_MS 5 #define LED_FLASH_MS 120 // ── Hall ISR ───────────────────────────────────────────────── volatile bool pulseFlag = false; volatile uint32_t lastPulseUs = 0; void IRAM_ATTR onPulse() { uint32_t now = micros(); if (now - lastPulseUs > (uint32_t)DEBOUNCE_MS * 1000UL) { pulseFlag = true; lastPulseUs = now; } } unsigned long flashStartMs = 0; unsigned long motorCycleMs = 0; bool motorOn = false; // ───────────────────────────────────────────────────────────── void setup() { // Motor — plain GPIO, no PWM pinMode(PIN_MOTOR, OUTPUT); digitalWrite(PIN_MOTOR, LOW); // LED — PWM for soft flash ledcAttach(PIN_LED_PWM, PWM_FREQ_LED, PWM_RES); ledcWrite(PIN_LED_PWM, 0); pinMode(PIN_HALL, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(PIN_HALL), onPulse, FALLING); setupWiFiOTA(); // Start first motor ON cycle digitalWrite(PIN_MOTOR, HIGH); motorOn = true; motorCycleMs = millis(); } // ───────────────────────────────────────────────────────────── void loop() { handleOTA(); unsigned long now = millis(); // Motor on/off cycle if (motorOn && now - motorCycleMs >= MOTOR_ON_MS) { digitalWrite(PIN_MOTOR, LOW); motorOn = false; motorCycleMs = now; } else if (!motorOn && now - motorCycleMs >= MOTOR_OFF_MS) { digitalWrite(PIN_MOTOR, HIGH); motorOn = true; motorCycleMs = now; } // Hall pulse → LED flash if (pulseFlag) { pulseFlag = false; flashStartMs = now; ledcWrite(PIN_LED_PWM, 255); } if (now - flashStartMs >= LED_FLASH_MS) { ledcWrite(PIN_LED_PWM, 0); } }