Yes, I'm trying to detect a signal edge (or maybe more accurately, a change of switch state from a short open state to closed). I also think that debouncing is the answer - I'm reading up on it right now.
Let me explain what I'm really trying to do.It's a home automation project to control simple on/off room lighting.
The wife isn't at all keen on push buttons, and I'll be fitting conventional switches (normal single pole changeover switches, SPDT) throughout the house to start with. I'd like to reuse these. I'll be running CAT5E cable from every light switch box back to the central hub, for use as signal cabling. What I'm thinking of doing when I automate is to first disconnect the mains power from the light switches, and then reuse the same switches to send a 12V signal back to the Arduino-based control system (there'll be no mains anywhere near the switch from then on). My idea is to connect the 2 switched contacts L1 and L2 of the switch together, such that the switch is on in either position. Run 2 signal cables back to the Arduino, one from the switch's common, the other from the shorted together L1 & L2. Use this to give a constant 5 volt signal to a digital pin, which it will do almost all of the time.
The only time that it won't will be when someone operates the switch, and as they're break before make switches, there should be a very brief interruption of the signal. Use this to trigger an "if off then turn on, or if on then turn off" event to control the power relay. It means that there'll no longer be a relationship between a switch's position (up for on, down for off etc), but this is already the case with dual switch upstairs / downstairs switching - so it shouldn't be a problem.
I don't actually know how long the switch will be in the open position for as it's being switched - I'm guessing in the order of 100ms or so, and I can see that there'll be lots of contact bounce (these are off the shelf DIY store switches, not lab quality ones with unobtanium contacts). But I think all I have to do is capture one 'contacts close' event for the code to work. If debouncing is necessary, then I'd rather do it with software, as any hardware solution would need to be repeated for 30 or more switches.
It means that I get to reuse the old switches, and whichever position they're in, an external source can still be used to switch lights on or off (ie. instigating a mood lighting preset routine) by injecting a short 'off' pulse. It also makes 'upstairs / downstairs' switching easy - just wire the signal cables in series, and any switch being operated will send a break & make signal. No limit to how many switches can be daisy chained in this way - try that with conventional home wiring!
Thanks,
Ian