bitwise to debounce and one-shot

I am using shift register for the interface with some buttons.

Debouncing is really easy with AND to work out if the button was pressed before.

now AND last
01 AND 11 = 01

Now in my head it should be easy to work out a "one shot" for buttons that are just pressed once and not held - i.e work out buttons that have changed their state to HIGH:

(last XOR now) & now
(01 XOR 11) & 11
(10) & 11 = 10

But I can't quite figure it out in my head - I end up cancelling out the XOR with the debounce.

Any ideas - I'm sure this is a simple one...

James

I think you're trying to squeeze too much information out of "now" and "last".

You will probably need a nowDebounced and lastDebounced to get it to work.

  • Brian

Figured this out last night right after I posted :slight_smile: typical :slight_smile:

thisByte = shiftIn();
deByte = thisByte & prevByte;
changeByte = (prevDeByte ^ deByte) & deByte;
prevByte = thisByte;
prevDeByte = deByte;

James