Hi
I have my code running well for a stepper motor/weird clock I am working on.
I am using switch/mode to trigger different timings on the motor.
I want to be able to interupt case 2 when it is running by pressing startBswitch and have it immediatly go to case 0, stopping the sequence.
Currently it works but only if I hold down the switchB for more than 6 seconds, which I assume is due to it needing to clear the
6545ms delay I have running for every sequence in the mode. The delay is required for adjusting my timings on the stepper
and I cant really touch it.
Is there a way of having the button press immediately interrupt case 2, regardless of whether it is in the delay period?
Here is the relevent part of the code:
void loop() {
if ( mode == 0 && digitalRead (setupAswitch) == LOW){ mode = 1;}
if ( mode == 0 && digitalRead (startAswitch) == LOW){ mode = 2;}
if ( mode == 2 && digitalRead (startBswitch) == LOW){ mode = 0;}
switch (mode){
case 0: // do nothing and reset all counters
motor.release();
CountA = 0;
CountB = 0;
CountC = 0;
break;
///
///
case 1: // Set Clock(Stepper) start position A
motor.setSpeed(100);
motor.step(1, BACKWARD, DOUBLE);
if (digitalRead(reedswitchA) == LOW) mode = 8; // Stop shen it hits reedswitch go to mode 8 (REED discrepancy)
break;
///
///
case 2: // Run Stepper Prog A
motor.setSpeed(100);
motor.step(2, BACKWARD, SINGLE);
if ( CountA++ >776 ) mode = 0 ;
delay (6545); //6545ms delay
break;