Move the limit switch on the elevator/gantry system to become a true interrupt instead of serviced depending on state in the loop():
void loop() {
sCmd.readSerial(); // We don't do much, just process serial commands
dnsServer.processNextRequest(); // wifi related
// Response to limit switch hardware interrupt
if (endStopHighTrigger && gantry.state == MOTOR_UP) {
set_motor_state(&gantry, MOTOR_OFF);
endStopHighTrigger = false;
Serial.println("endStopHigh");
}
if (endStopLowTrigger && gantry.state == MOTOR_DOWN) {
set_motor_state(&gantry, MOTOR_OFF);
endStopLowTrigger = false;
Serial.println("endStopLow");
}
if (dispenseInProgress) dispenseDrink(); // Dispense routine gets called repeatedly when dispenseInProgress flag is high
readButtons(); // Read inputs on every loop
// Clean up socket connections
ws.cleanupClients();
}
Move the limit switch on the elevator/gantry system to become a true interrupt instead of serviced depending on state in the loop():