Can't seems to make it work

While this may be part of a larger, more complex project, or a learning experience- you certainly decided to do it the hard way.

A simple state machine would be more than enough to perform this functionality.