// SmartI8 (DI=8, DO=8, AI=8) - Water tank fill pump with inverter // DO1: START pulse 4s // DO2: STOP pulse 4s (while 1, inverter will not start) // DO3: EMERGENCY (while 1, inverter will not start) // IN1: level low, IN2: level high // IN3: emergency mushroom, IN4: power fault => emergency // IN5: manual ON (test), IN6: manual OFF (test) SCAN_MS = 200; START_MS = 4000; STOP_MS = 4000; // Initialization out(1) = 0; out(2) = 0; out(3) = 0; pump = 0; prev_pump = 0; // Output pulse helper (MACRO locals prefixed with '_' to avoid collisions) macro PULSE_DO(_idx, _ms) { out(_idx) = 1; delay(_ms) { out(_idx) = 0; } } every(SCAN_MS) { emg = in(3) || in(4); // Emergency output to inverter out(3) = emg; // Requests stop_req = emg || in(2) || in(6); start_req = (in(1) && !in(2)) || in(5); // Inhibit start when STOP or EMG is active allow_start = (out(2) == 0) && (out(3) == 0) && (in(6) == 0); // Tank fill logic: start on low, stop on high, emergency always stop if (stop_req) { pump = 0; } else { if (start_req && allow_start) { pump = 1; } } // Transitions -> pulses to inverter if (pump && !prev_pump) { PULSE_DO(1, START_MS); } if (!pump && prev_pump) { PULSE_DO(2, STOP_MS); } prev_pump = pump; } // Optional telemetry heartbeat (remove if not needed) every(60000, "status") { publish("status", "low", in(1), "high", in(2), "emg", out(3), "pump", pump); }