I used to use these quite often in circuit designs back in the 70s.
FYI
I did some analysis of your library with the following results:
I modified your library so timing marks were outputted on pin 11 (orange trace), lines 76-77, see the code below.
/*
*EdgeDebounce.cpp
*Created by: Jacques bellavance, July 7 2017
*Released into the public domain
*GNU GENERAL PUBLIC LICENSE V3
*
*This library is designed to debounce switches.
*It was inspired by this article: http://www.ganssle.com/debouncing.htm
*It is designed to be lightweight
*PSEUDOCODE
* 1) Repeat
* 1) Read the switch 16 times
* 2) Until all reads are identical
* 3) Return the switch's status
*
*The number of times the switch is repetitively read can be set between 1 and 32
*Switches can use either an external pulldown resistor or the internal pullup resistor
*pinMode() is set by the constructor
*/
#include <Arduino.h>
#include "EdgeDebounce.h"
//Constructor===============================
//pin: the pin connected to the switch
//------------------------------------------
EdgeDebounce::EdgeDebounce(byte pin, byte mode) {
MYpin = pin;
if (mode == PULLUP) {
pinMode(pin, INPUT_PULLUP);
MYmode = PULLUP;
}
else {
pinMode(pin, INPUT);
MYmode = PULLDOWN;
}
}//Debounce---------------------------------
//setSensitivity==================================================================
//Sets the number of times a switch is read repeatedly by the debouncer routine
//It defaults to 16 times. Allowable values are 1..32
//--------------------------------------------------------------------------------
void EdgeDebounce::setSensitivity(byte w) {
if (w >= 1 && w <= 32) {
MYsensitivity = w;
debounceDontCare = 0xffffffff;
for (byte i = 0; i < w; i++) debounceDontCare = debounceDontCare << 1 | 0;
}
}//setSensitivity--------------------------------------------------------------------
//getSensitivity==================================================================
//Returns the current sensitivity of Debounce
//--------------------------------------------------------------------------------
byte EdgeDebounce::getSensitivity() {
return MYsensitivity;
}//getSensitivity--------------------------------------------------------------------
//pressed=========================================================================================================
//Debounces the switch connected to "MYpin"
//The switch is read 16 times (~60us) to look for 16 consecutive HIGH or LOW
//If unsuccessfull, it means that a change is occuring at that same moment
//and that either a rising or falling edge of the signal is actualy occuring.
//The pin is reread repetetively 16 times until the edge is confirmed.
//If the switch has been declared PULLDOWN: Returns 0 if open or 1 if closed
//If the switch has been declared PULLUP: Returns 1 if open or 0 if closed
//---------------------------------------------------------------------------------------------------------------
int EdgeDebounce::pressed() {
unsigned long pinStatus;
do {
pinStatus = 0xffffffff;
for (byte i = 1; i <= MYsensitivity; i++)
{
// 111100
// 321098
PINB = 0b00001000; //toggle pin 11
PINB = 0b00001000; //toggle pin 11
pinStatus = (pinStatus << 1) | digitalRead(MYpin);
}
} while ((pinStatus != debounceDontCare) && (pinStatus != 0xffffffff));
return byte(pinStatus & 0x00000001);
}//pressed--------------------------------------------------------------------------------------------------------
//closed==============================================
//Returns true if the switch is closed (or ON)
//-----------------------------------------------------
bool EdgeDebounce::closed() {
if (MYmode == PULLUP)
{
return !pressed();
}
else
{
return pressed();
}
}//closed---------------------------------------------
Your Basic_Pullup sketch was modified so timing marks were outputted on pin 10 (red trace), lines 32-33, see the code below.
/*
Basic-Pullup.ino
By Jacques Bellavance, July 7 2017
Shows how to use the Debounce Library
This sketch is for switches that uses the internal pullup resistor
Switch pin A : Ground
Switch pin B : Arduino's pin 2
*/
#include <EdgeDebounce.h>
#define BUTTON_PIN 8
//Create an instance of Debounce and name it button
//button is tied to pin BUTTON_PIN and is in PULLUP mode
EdgeDebounce button(BUTTON_PIN, PULLUP);
void setup()
{
pinMode(11, OUTPUT); //Orange trace, created in library
pinMode(10, OUTPUT); //Red trace, created in this sketch
pinMode(13, OUTPUT);
//The Library has declared pinMode(BUTTON_PIN, INPUT_PULLUP) for you
}
void loop()
{
if (button.closed())
{
// 111100
// 321098
PINB = 0b00000100; //toggle pin 10
PINB = 0b00000100; //toggle pin 10
digitalWrite(13, HIGH); //The .closed method returns true if there is contact
}
else
{
digitalWrite(13, LOW);
}
}
Here is the input signal that was fed to input pin 8:

This is a magnified view showing all 3 signals:
EDIT The image below is wrong, see post #39 for the correct image.
You can see (for the most part) it takes 16 samples between each write to the LED.
I cannot explain why it appears there are 22 pulses before the first double LED writes, I would have guessed 16.
Why, when the input is HIGH, there is one LED write and why, when the input is LOW, there are two LED writes?
This is a bit confusing.
I will have to look a bit deeper to explain this.
The above images demonstrate one technique on how to analyze what is happening in hardware when code is executed.
.