Hello, I added code tags for you for this time but do yourself a favour and please read How to get the best out of this forum
we are missing a diagram describing how things (what things) are wired together.
your code is complicated to read because variables do not convey any meaning. what does it mean if x is HIGH or LOW ? (and what is x anyway). What does state 0 represent (you could use enum to get more meaningful names instead of 0 and 1 - or just use a bool if you have 2 states)
what's the use for
case 0: state = 0; break;
if you enter the if that leads to that switch/case, you know state is 0 already...
what is a revolution?