It is definitely suitable.
If you don’t have a sensor to triggger an event because it’s just « wait for 5s in that state » - that’s OK. Timeout can be an event too.
Here is an example, typed here - untested
enum State { WAITING_FOR_ACTIVATION, PROCESSING };
State currentState = WAITING_FOR_ACTIVATION;
constexpr byte sensorPin = 2;
unsigned long startTime = 0;
void stateMachine() {
switch (currentState) {
case WAITING_FOR_ACTIVATION:
if (digitalRead(sensorPin) == LOW) {
startTime = millis();
Serial.println("Activated! Processing...");
currentState = PROCESSING;
}
break;
case PROCESSING:
if (millis() - startTime >= 5000) {
Serial.println("Processing done. Back to waiting.");
currentState = WAITING_FOR_ACTIVATION;
}
break;
}
}
void setup() {
Serial.begin(115200);
pinMode(sensorPin, INPUT_PULLUP);
Serial.println("Waiting for activation");
}
void loop() {
stateMachine();
}
Here is a small introduction to the topic: Yet another Finite State Machine introduction