Adafruit_RGB_LCD SHIELD FINITE STATE MACHINE PROJ

personally I think it is not a good idea to rely on the order of enum entries nor to give the enum elements a specific value. IMHO a state machine should describe what is the next step when a specific event in a specific state occures.

When you google how to iterate over an enum you might find some ideas.
Even if downvoted by others I find this option the least worst one, easy to follow and working for the Arduino / C++11: the overload of the ++ operator:
https://stackoverflow.com/questions/261963/how-can-i-iterate-over-an-enum/58983366#58983366

I've implemented a Proof of Concept in my Sketch from post #11 and it seems to compile and work

enum class State { FIXTEXT, RUNTIME, RANDOM} state;      // what kind of data should be shown
//based on https://stackoverflow.com/questions/261963/how-can-i-iterate-over-an-enum/58983366#58983366
State& operator++(State &c, int)
{
  switch (c)
  {
    case State::FIXTEXT:
      return c = State::RUNTIME;
    case State::RUNTIME:
      return c = State::RANDOM;
    case State::RANDOM:
      return c = State::FIXTEXT; // managing overflow
  }
  return c;                      // avoid warning
}

this gives you a ++ operator for the state:

        //state = State::RUNTIME;  // replaced testwise
        state++; // testwise
2 Likes