Lab6 according to state machine