Since a few people asked for it...
Code
const
DebounceLogic : array [0..15] of byte = (%0000, %0010, %0100, %0110, %0000, %0010, %0100, %1110,
%0000, %1010, %1100, %1110, %1000, %1010, %1100, %1110);
// 3 key debounce array.
UnDebounced : byte = 0; // un-debounced input bit location
Debounced : byte = 3; // debounced bit location
var
Inputs : array [0..17] of byte; // debounce control
function fDebounce( Location : byte; Value : boolean ) : boolean;
begin
Setbit( Inputs[ Location ], Undebounced, Value );
Inputs[ Location ] := DebounceLogic[ Inputs[ Location ]];
return( bit( Inputs[ Location ], debounced ));
end;
It is meant to be quite fast. If you only have 1 input, obviously you don't need the array 'Inputs' which will make things run faster. The output only changes state when 3 successive input have the same value.