Based on the Debounce example code that comes with the IDE with a light tweak to make into a state change switch instead of a momentary switch.
See this blog post for the example code.
Loading more stuff…
Hmm…it looks like things are taking a while to load. Try again?