Jeff’s code

My code

normal push-button

detects single/double click

detects single/double click

reed switch

detects single/double click

detects a single click every sodding time and it’s driving me nuts!

What I'm trying to do

I've got some multi-colour LED strips in my kitchen. When you turn them on, they light up white.

As a hidden extra for parties, when I close a particular cupboard door twice in quick succession (a "double-click") the LEDs fade slowly to black, and then go into "disco mode", where they select a random colour, glide slowly to that colour, and hold it for 30 seconds, before selecting a new colour and gliding to that.

Double-slamming the cupboard again makes the lights glide back to white.

What actually happens

All the above works perfectly, as long as I use a push-button instead of a real cupboard door.

To make a discreet installation in the kitchen cupboard though, I've installed a reed switch in the door frame, and a small magnet in the door. And here's the problem: when it's the reed switch making and breaking the contact instead of a normal push button, my code never detects a double-click. It's a single click every time.

What I've tried

This leads me to think that I've done something subtlely stupid in adapting Jeff's code into my code. But I can't find what.

Update 2012-05-14: I found a different reed switch kicking around, which has a N/O and N/C connection available. And, weirdly, when I use the N/C leg, I get the same bad results as with the other N/C reed switch; but when I use the N/O leg, it works!

I'm going to pick up a housed N/O reed switch tomorrow and see if that does the job.

If you can help...

I'll give you a huge round of applause. I'll buy you a beer. I'll cook you dinner. You can marvel at the pretty LED lights in my kitchen while I'm cooking.

Please email your suggestions to Thanks!