Hello!
It looks good (essentially), although I haven't run it to verify if it works.
But why do you use 2 definitions, POSITIVE and POSITIVE_HALF_CYCLE. It looks more or less the same thing.
And the 2 variables you use change exactly under the same conditions, which makes me think that currentstate
is always equal to current_half_cycle. So you can get rid of one of them.
Beside this, be careful, one case is not covered:
In you loop you have if something <, then if something >. What about if something ==?
Dora.