one issue with your code is recognizing a button press during a delay.
consider, which will recognize a button press as soon as it occurs and handles a press in the middle of a cycle, completing a "Purge"
#undef MyHW
#ifdef MyHW
const byte pinBut = A1;
const byte pinMotA = 12;
const byte pinMotB = 13;
# define OneMinute (2 * 1000L)
#else
const byte pinBut = 2;
const byte pinMotA = 3;
const byte pinMotB = 4;
# define OneMinute (60 * 1000L)
#endif
byte butState;
enum { Off, Forward, Pause, Reverse, Idle, Purge };
int state = Off;
const char *stateStr [] = {
"Off", "Forward", "Pause", "Reverse", "Idle", "Purge" };
unsigned long msecLst;
unsigned long period;
// -----------------------------------------------------------------------------
void motor (
int operation)
{
byte motA = LOW;
byte motB = LOW;
switch (operation) {
case Forward:
motA = HIGH;
break;
case Reverse:
motB = HIGH;
break;
}
digitalWrite (pinMotA, motA);
digitalWrite (pinMotB, motB);
}
// -----------------------------------------------------------------------------
void loop ()
{
unsigned long msec = millis ();
byte but = digitalRead (pinBut);
if (butState != but) {
butState = but;
delay (10); // debounce
if (HIGH == but) {
if (Off == state) {
state = Idle;
period = 0;
}
else {
state = Purge;
motor (Reverse);
msecLst = msec;
period = OneMinute;
}
}
}
if (Off != state && (msec - msecLst) > period) {
msecLst = msec;
Serial.print (stateStr [state]);
Serial.print (" - ");
switch (state) {
case Idle:
state = Forward;
period = OneMinute;
break;
case Forward:
state = Reverse;
period = OneMinute;
break;
case Reverse:
state = Idle;
period = 10 * OneMinute;
break;
case Purge:
state = Off;
break;
}
Serial.println (stateStr [state]);
motor (state);
}
}
// -----------------------------------------------------------------------------
void setup ()
{
Serial.begin (9600);
pinMode (pinBut, INPUT);
butState = digitalRead (pinBut);
pinMode (pinMotA, OUTPUT);
pinMode (pinMotB, OUTPUT);
}