Sequential keys

I can not find a solution to read two keys and have the validation of the following sequence:
00, 01,10, 11 and 00 and also for 00, 10, 01, 11 and 00. At the transition from 11 to 00 a byte is valid. A different byte for each case. If the sequence is not completed in both cases, it is necessary in a time of 300ms, to return to 00. Could they help me

Do a search on state machines since that is the construct you need to achieve this.

Peter

Thank you. I have already written the function for the state machine. Sorted out.