// by NMDW COTMD/
int input_pin = 5; // input pin number
int switch_bounce_time = 10; // adjust bounce time depend on the switch (mechanical vibration)
unsigned long time1 =0;
unsigned long time2 =0;
unsigned long bouncechecktime = 0;
bool input_Status = false;
bool Prvious_input_Status = false;
bool debounce_Status = false;
bool prv_debounce_Status = false;
bool debounce_status_changed = false;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(input_pin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
input_Status = digitalRead(input_pin);
if( not Prvious_input_Status && input_Status) // Previous low and current high i.e. rising edge
{
//Serial.println("Rising Edge");
if(millis() - bouncechecktime > switch_bounce_time)
{
debounce_Status = input_Status;
bouncechecktime = millis();
}
}
if(Prvious_input_Status && not input_Status) // Previous low and current high i.e. rising edge
{
//Serial.println("Falling Edge");
if(millis() - bouncechecktime > switch_bounce_time)
{
debounce_Status = input_Status;
bouncechecktime = millis();
}
}
debounce_status_changed = (prv_debounce_Status != debounce_Status);
if(debounce_status_changed)
{
Serial.print("Debounced Status : ");
Serial.println(debounce_Status);
if (debounce_Status)
{
Serial.println("Debounce Rising Edge");
}
else
{
Serial.println("Debounce falling Edge");
}
}
prv_debounce_Status = debounce_Status;
Prvious_input_Status = input_Status;
}
nano:12
nano:11
nano:10
nano:9
nano:8
nano:7
nano:6
nano:5
nano:4
nano:3
nano:2
nano:GND.2
nano:RESET.2
nano:0
nano:1
nano:13
nano:3.3V
nano:AREF
nano:A0
nano:A1
nano:A2
nano:A3
nano:A4
nano:A5
nano:A6
nano:A7
nano:5V
nano:RESET
nano:GND.1
nano:VIN
nano:12.2
nano:5V.2
nano:13.2
nano:11.2
nano:RESET.3
nano:GND.3
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r
r1:1
r1:2