This library is togle sw on/off edge and level decision. input sw level noise and chatting cancel. MDX-20 controler用
Fork of DigitalSw by
Diff: DigitalSw.cpp
- Revision:
- 3:ea853fc7172d
- Parent:
- 2:08137bac3611
diff -r 08137bac3611 -r ea853fc7172d DigitalSw.cpp --- 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;