Uno R3 Test Box

You described a state machine very well. Search the forum for implementations.

Turn your numbered items into states (enum...). In each state wait for the expected events and react and proceed as described.