Keep PWM signal in loop with other things

See the StateChangeDetection example, how to react on button state changes only. Whenever the button state changes, start or stop the PWM output.