This library is push button or dipSw noise cancel and on/off edge recognition

Dependents:   led-sound_checker clockGenerator

Fork of DigitalSw by suu pen

sample program "DigitalSW_hello" https://developer.mbed.org/users/suupen/code/DigitalSW_hello/rev/ffa16c2a347f

Revision:
3:ea853fc7172d
Parent:
2:08137bac3611
--- a/DigitalSw.cpp	Thu Oct 27 02:03:28 2016 +0000
+++ b/DigitalSw.cpp	Thu Oct 27 06:35:32 2016 +0000
@@ -7,12 +7,12 @@
 /**
  *
  */
-DigitalSw::DigitalSw(PinName sw
-                    ) : _sw(sw)
+DigitalSw::DigitalSw(PinName sw, PinMode pull = PullUp
+                    ) : _sw(sw), _pull(pull)
 {
 
     reset();
-    _sw.mode(PullUp);
+    _sw.mode(_pull);
 
     _swCheckPeriod.attach_us(this, &DigitalSw::swCheck, 10000);
 
@@ -54,7 +54,12 @@
 {
     static uint8_t levelBuffer = 0;
 
+    if(_pull == PullUp){
     levelBuffer = (levelBuffer << 1) | !_sw;
+    }
+    else{
+    levelBuffer = (levelBuffer << 1) | _sw;
+        }
 
     if(levelBuffer == 0x00) {
         _levelNow = 0;