It sounds like you only have two states:
- Wait for four seconds (unless a button is pressed first).
- Switch to the next phrase.
A State Machine might be overkill for that. ![]()
I would try something like:
void loop()
{
static unsigned long startOfTimer = 0;
unsigned long currentMillis = millis();
if (currentMillis - startOfTimer >= 4000)
{
startOfTimer = currentMillis;
// Switch to new phrase
}
static bool buttonWasPressed = false;
bool buttonIsPressed = digitalRead(ButtonPin) == LOW;
if (buttonIsPressed != buttonWasPressed)
{
// State Change Detected
buttonWasPressed = buttonIsPressed;
if (buttonIsPressed)
{
// Switch to new phrase
startOfTimer = currentMillis();
}
}