This library is push button or dipSw noise cancel and on/off edge recognition
Dependents: led-sound_checker clockGenerator
Fork of DigitalSw by
sample program "DigitalSW_hello" https://developer.mbed.org/users/suupen/code/DigitalSW_hello/rev/ffa16c2a347f
Revision 3:ea853fc7172d, committed 2016-10-27
- Comitter:
- suupen
- Date:
- Thu Oct 27 06:35:32 2016 +0000
- Parent:
- 2:08137bac3611
- Child:
- 4:1ae29d30a441
- Commit message:
- This commit is PinMode(PullUp or PullDown) select
Changed in this revision
DigitalSw.cpp | Show annotated file Show diff for this revision Revisions of this file |
DigitalSw.h | Show annotated file Show diff for this revision Revisions of this file |
--- 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;
--- a/DigitalSw.h Thu Oct 27 02:03:28 2016 +0000 +++ b/DigitalSw.h Thu Oct 27 06:35:32 2016 +0000 @@ -76,7 +76,7 @@ * @param sw pin * @note nothing */ - DigitalSw(PinName sw); + DigitalSw(PinName sw, PinMode pull); /** * Reset the edge and level. @@ -114,6 +114,7 @@ DigitalIn _sw; + PinMode _pull; volatile int16_t _onEdge; volatile int16_t _offEdge; volatile int16_t _levelNow;