Control by time cycles

You might want to think about 'when a switch goes HIGH/LOW', not while the switch is HIGH/LOW.

See change in state.