Hi, endlich bin ich dazu gekommen deinen Code ausgiebig zu nutzen und den Versuch gestartet, es auf mein Vorhaben umzulegen. Doch so ganz will es noch nicht klappen. Der "Haarknoten" hängt wohl noch irgendwo fest. 
Ich habe mal einfach meinen gesamten Sketch eingesetzt, damit du meinen Stand sehen kannst. Ja, es ist noch viel Luft zum kürzen und zu vereinfachen, aber für mich ist es noch übersichtlicher. Wenn alles so läuft, wie ich es mir vorstelle, dann wird optimiert. Daher geh nicht so hart mit mir ins Gericht.

Nun erstmal zu meinen Problempunkten. Insgesamt gibt es 5 Positionen, an der die "gleichen" Füll- und Prüfvorgänge ablaufen sollen. An den Positionen 1-4 sind noch meine ersten Grundgerüste zu sehen (welche so funktionieren, aber ohne die Abfrage, ob der Reed-Schalter nach dem Ablauf erst wieder geöffnet wurde, um erst danach wieder von vorn zu beginnen und mit Delay als meine Laien-"Notlösung".).
An Position 5 habe ich versucht deinen Lösungsvorschlag umzusetzen. Sobald ich den Kontakt schließe beginnt der switchcase zu starten. Soweit schonmal gut.
Der erste Case greift und der Stepper fährt an die Position 5 des zweiten Case, aber schaltet hier nicht das Relais ein. Springt in den dritten Case und fährt nach den millis den Stepper zurück und die LED schaltet, wie erwartet wieder ein. Also das Relais wird völlig ignoriert und hab null Ideen, warum es ignoriert wird.
Die letzte Prüfung, ob der Reed nach dem durchlaufen erst wieder geöffnet wurde, um dann erst erneut mit dem ganzen Ablauf zu starten fehlt noch. Oder ich hab dich dort missverstanden, oder du mich.
Vielleicht hast du Gelegenheit und schaust mal drüber.
/*
Stepper filling station by m0rph3xx https://forum.arduino.cc/u/morphexx/summary
Driver DRV8825 from AZ
*/
//----------------------------------------------------------------------------------------------------------------------
//STEPPER AND home_switch (MICROSWITCH)
#include <AccelStepper.h> // Library created by Mike McCauley at http://www.airspayce.com/mikem/arduino/AccelStepper/
// Define a stepper and the pins it will use
#define dir_pin 2 // Pin 2 connected to DIR pin
#define step_pin 3 // Pin 3 connected to STP pin
// #define MS0 x // Pin x connected to MS1 pin
// #define MS1 x // Pin x connected to MS1 pin
// #define MS2 x // Pin x connected to MS2 pin
// #define SLEEP_PIN x // Pin x connected to SLEEP pin
AccelStepper stepper(AccelStepper::DRIVER, step_pin, dir_pin); // Pin 2 connected to STP pin and Pin 3 connected to DIR pin of AZ DRV8825
int position[5] = { 90, 165, 240, 315, 395 }; // Number of steps for positions 1-5 of the shot glasses
int home_switch = 10; //PIN home switch (MICROSWITCH) - Pin to set home/zero for stepper after startup/reset
//----------------------------------------------------------------------------------------------------------------------
// REED SWITCH AND LED
int switch_pin_01 = 4; //PIN Reed switch 1
int led_pin_01 = A1; //PIN LED 3mm green 1
int switch_pin_02 = 5; //PIN Reed switch 2
int led_pin_02 = A2; //PIN LED 3mm green 2
int switch_pin_03 = 6; //PIN Reed switch 3
int led_pin_03 = A3; //PIN LED 3mm green 3
int switch_pin_04 = 7; //PIN Reed switch 4
int led_pin_04 = A4; //PIN LED 3mm green 4
int switch_pin_05 = 8; //PIN Reed switch 5
int led_pin_05 = A5; //PIN LED 3mm green 5
//----------------------------------------------------------------------------------------------------------------------
//RELAY AND BUTTON
int relay_pin = 9; //PIN RELAY - Relay requires 5V
int button_grey_pin = 11; //PIN BUTTON GREY - Pin to activate the relay (pump) manually via grey foil button
constexpr bool relayOn{ HIGH }; // Turn relay on
constexpr bool relayOff{ !relayOn }; // Turn relay off
//----------------------------------------------------------------------------------------------------------------------
enum class STATUS_05 { checkSwitch_05,
stepONE_05,
stepTWO_05 }; // Switch case for switch 5 of 5 in total
STATUS_05 status_05 = STATUS_05::checkSwitch_05; // Status (switch case) for switch 5 of 5 in total
uint32_t lastSwitchTime;
//----------------------------------------------------------------------------------------------------------------------
void setup() {
//STEPPER HOMING WITH home_switch - Enable internal pull-up for the switch
pinMode(home_switch, INPUT_PULLUP);
pinMode(dir_pin, OUTPUT);
pinMode(step_pin, OUTPUT);
// pinMode(MS0, OUTPUT);
// pinMode(MS1, OUTPUT);
// pinMode(MS2, OUTPUT);
// pinMode(SLEEP_PIN, OUTPUT);
// digitalWrite(SLEEP_PIN, HIGH); // Wake up AZ DRV8825
// delay(5); // Wait for stepper driver wake up
/* Configure type of Steps on AZ DRV8825:
The DRV8825 driver has three input pins for microstep resolutions:
" MS0
" MS1
" MS2
By setting appropriate logic levels on these pins, we can set the drive mode of the motor to
drive mode of the motor to one of these six modes:
M0 M1 M2 Microstep resolution
LOW LOW LOW Full step
HIGH LOW LOW Half step
LOW HIGH LOW Quarter step
HIGH HIGH LOW Eighth step
LOW LOW HIGH Sixteenth step
HIGH LOW HIGH 1/32 step
LOW HIGH HIGH 1/32 step
HIGH HIGH HIGH 1/32 step
Remember that you don’t need to manually set the pins
The DRV8825 handles this configuration for you based on the desired mode.
Alternatively, to save pins on the microcontroller, the modes can be permanently connected
via the 5V pin of the controller (5V=HIGH, disconnected=LOW).
*/
// digitalWrite(MS0, LOW); // Configures to Full Steps
// digitalWrite(MS1, LOW); // Configures to Full Steps
// digitalWrite(MS2, LOW); // Configures to Full Steps
//----------------------------------------------------------------------------------------------------------------------
// Start homing of stepper motor at startup
while (digitalRead(home_switch)) { // Do this until the switch is activated
digitalWrite(dir_pin, LOW); // (HIGH = anti-clockwise / LOW = clockwise)
digitalWrite(step_pin, HIGH);
delay(5); // Delay to slow down speed of Stepper
digitalWrite(step_pin, LOW);
delay(5);
}
while (!digitalRead(home_switch)) { // Do this until the switch is not activated
digitalWrite(dir_pin, HIGH);
digitalWrite(step_pin, HIGH);
delay(10); // More delay to slow even more while moving away from switch
digitalWrite(step_pin, LOW);
delay(10);
}
stepper.setMaxSpeed(1000); // Set Maximum Speed of stepper (Slower to get better accuracy)
stepper.setAcceleration(400); // Set acceleration of stepper
stepper.setCurrentPosition(0); // Set the current position to 0 steps
//----------------------------------------------------------------------------------------------------------------------
// REED SWITCH AND LED - Enable internal pull-up for the reed switch - LED on
pinMode(switch_pin_01, INPUT_PULLUP);
pinMode(led_pin_01, OUTPUT);
digitalWrite(led_pin_01, HIGH); // Turn LED 1 on
pinMode(switch_pin_02, INPUT_PULLUP);
pinMode(led_pin_02, OUTPUT);
digitalWrite(led_pin_02, HIGH); // Turn LED 2 on
pinMode(switch_pin_03, INPUT_PULLUP);
pinMode(led_pin_03, OUTPUT);
digitalWrite(led_pin_03, HIGH); // Turn LED 3 on
pinMode(switch_pin_04, INPUT_PULLUP);
pinMode(led_pin_04, OUTPUT);
digitalWrite(led_pin_04, HIGH); // Turn LED 4 on
pinMode(switch_pin_05, INPUT_PULLUP);
pinMode(led_pin_05, OUTPUT);
digitalWrite(led_pin_05, HIGH); // Turn LED 5 on
//----------------------------------------------------------------------------------------------------------------------
// RELAY AND BUTTON - Enable internal pull-up for the button
pinMode(relay_pin, OUTPUT);
pinMode(button_grey_pin, INPUT_PULLUP);
digitalWrite(relay_pin, LOW); // Turn the RELAY off
}
//----------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------
void loop() {
prefilling(); // Pre-fill the hose with function prefilling
//----------------------------------------------------------------------------------------------------------------------
// FILLING SHOT GLASSES - Stepper moves to 1 of the 5 positions of the shot glasses
if (digitalRead(switch_pin_01) == LOW) {
delay(100);
digitalWrite(led_pin_01, LOW); // Turn the LED off
stepper.moveTo(position[0]); // Set desired move / Position defined by variable
stepper.runToPosition(); // Moves the motor to target position w/ acceleration/ deceleration and it blocks until is in position
filling(); // Filling the shot glass with function filling
backtohome(); // Move back to position 0 with funtion backtohome
digitalWrite(led_pin_01, HIGH); // Turn the LED on
}
//------------------
if (digitalRead(switch_pin_02) == LOW) {
delay(100);
digitalWrite(led_pin_02, LOW); // Turn the LED off
stepper.moveTo(position[1]); // Set desired move / Position defined by variable
stepper.runToPosition(); // Moves the motor to target position w/ acceleration/ deceleration and it blocks until is in position
filling(); // Filling the shot glass with function filling
backtohome(); // Move back to position 0 with funtion backtohome
digitalWrite(led_pin_02, HIGH); // Turn the LED off
}
//------------------
if (digitalRead(switch_pin_03) == LOW) {
delay(100);
digitalWrite(led_pin_03, LOW); // Turn the LED off
stepper.moveTo(position[2]); // Set desired move / Position defined by variable
stepper.runToPosition(); // Moves the motor to target position w/ acceleration/ deceleration and it blocks until is in position
filling(); // Filling the shot glass with function filling
backtohome(); // Move back to position 0 with funtion backtohome
digitalWrite(led_pin_03, HIGH); // Turn the LED on
}
//------------------
if (digitalRead(switch_pin_04) == LOW) {
delay(100);
digitalWrite(led_pin_04, LOW); // Turn the LED off
stepper.moveTo(position[3]); // Set desired move / Position defined by variable
stepper.runToPosition(); // Moves the motor to target position w/ acceleration/ deceleration and it blocks until is in position
filling(); // Filling the shot glass with function filling
backtohome(); // Move back to position 0 with funtion backtohome
digitalWrite(led_pin_04, HIGH); // Turn the LED on
}
//------------------
fillingGlassPos05(); // Test of the Position 5 for implementation with switch case as function
/*
if (digitalRead(switch_pin_05) == LOW) {
delay(100);
digitalWrite(led_pin_05, LOW); // Turn the LED off
stepper.moveTo(position[4]); // Set desired move / Position defined by variable
stepper.runToPosition(); // Moves the motor to target position w/ acceleration/ deceleration and it blocks until is in position
filling(); // Filling the shot glass with function filling
backtohome(); // Move back to position 0 with funtion backtohome
digitalWrite(led_pin_05, HIGH); // Turn the LED on
}
*/
//------------------
}
// ----------------------------------------------------------------------------------------------------------------------
void fillingGlassPos05() {
// Function: Filling shot glass on Position 5 out of 5 in total
switch (status_05) {
case STATUS_05::checkSwitch_05:
if (digitalRead(switch_pin_05) == LOW) {
delay(100);
status_05 = STATUS_05::stepONE_05;
}
break;
case STATUS_05::stepONE_05:
digitalWrite(led_pin_05, LOW); // Turn the LED off
stepper.moveTo(position[4]); // Set desired move / Position defined by variable
stepper.runToPosition(); // Moves the motor to target position w/ acceleration/ deceleration and it blocks until is in position
digitalWrite(relay_pin, relayOn); // Start filling the shot glass
lastSwitchTime = millis();
status_05 = STATUS_05::stepTWO_05;
break;
case STATUS_05::stepTWO_05:
if (millis() - lastSwitchTime > 2000) {
digitalWrite(relay_pin, relayOff); // Turn off relay (pump)
backtohome(); // Move back to position 0 with funtion backtohome
digitalWrite(led_pin_05, HIGH); // Turn the LED on
status_05 = STATUS_05::checkSwitch_05;
}
break;
}
}
void prefilling() {
// Function: RELAY AND BUTTON - If the button_grey_pin reads low, the button is pressed. To pre-fill the hose.
if (digitalRead(button_grey_pin) == LOW) {
delay(100);
digitalWrite(relay_pin, HIGH); // Turn the RELAY on for as long as the button is pressed
} else {
digitalWrite(relay_pin, LOW);
}
}
void filling() {
// Function: Filling shot glasses
digitalWrite(relay_pin, HIGH); // Turn on relay (pump)
delay(1000); // Filling time of the shot glass
digitalWrite(relay_pin, LOW); // Turn off relay (pump)
delay(1000); // Drip-off time of the filling hose
}
void backtohome() {
// Function: Returning the stepper to the zero point - Identical to homing routine in setup loop
while (digitalRead(home_switch)) { // Do this until the switch IS activated
digitalWrite(dir_pin, LOW); // (HIGH = anti-clockwise / LOW = clockwise)
digitalWrite(step_pin, HIGH);
delay(5); // Delay to slow down speed of Stepper
digitalWrite(step_pin, LOW);
delay(5);
}
while (!digitalRead(home_switch)) { // Do this until the switch IS NOT activated
digitalWrite(dir_pin, HIGH);
digitalWrite(step_pin, HIGH);
delay(10); // More delay to slow even more while moving away from switch
digitalWrite(step_pin, LOW);
delay(10);
}
stepper.setMaxSpeed(1000); // Set Maximum Speed of stepper (Slower to get better accuracy)
stepper.setAcceleration(400); // Set acceleration of stepper
stepper.setCurrentPosition(0); // Set the current position to 0 steps
}