Adafruit_RGB_LCD SHIELD FINITE STATE MACHINE PROJ

It sounds like you only have two states:

  1. Wait for four seconds (unless a button is pressed first).
  2. Switch to the next phrase.

A State Machine might be overkill for that. :slight_smile:

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();
    }
}
1 Like