So I made some changes to the code. First, I replaced the 1 second delay in the end of my mandmColor() function with this.
startMillis = millis();
currentMillis = millis();
while (currentMillis - startMillis <= period) {
currentMillis = millis();
checkButton();
}
Then, I changed my checkButton function to read this. This make it so that once it has received a command, it ignores all future commands until the command is relayed to the checkToggle function.
void checkButton() {
static int lastState = ! ISPRESSED;
int state = readButton();
if (buttonNewData == NO) {
if (state != lastState) {
if (buttonState == ISPRESSED) {
Serial.println("<Button>");
if ((toggle == PAUSE) || (toggle == RESTART)) {
toggle = START;
buttonNewData = YES;
}
else if (toggle == START) {
toggle = PAUSE;
buttonNewData = YES;
}
}
lastState = state;
}
}
}
Finally, this line is added to my checkToggle function so that my button will now accept new data.
buttonNewData = NO;
I also toopk your advice and defined the numbers with meaningful names.
#define YES 1
#define NO 0
#define START 0
#define PAUSE 1
#define RESTART 2
#define TERMINATE 3
As of right now, everything works great the first time through. I can use the button to start the sorter, then pause it, and restart it. However, it will not pause a second time, it simply ignores the button imput.
Is there any way to fix this, thanks in advance, DH
MM_Sorter_shift_toggle_servo_count9.ino (11.3 KB)