A debouncing InterruptIn wrapper
Diff: ButtonIn.cpp
- Revision:
- 2:c353357a97e4
- Parent:
- 1:e806603f0088
--- a/ButtonIn.cpp Tue Feb 07 09:31:26 2012 +0000 +++ b/ButtonIn.cpp Tue Feb 07 10:35:38 2012 +0000 @@ -1,3 +1,22 @@ +/* +ButtonIn is a debouncing InterruptIn class for mbed (http://mbed.org). + +Copyright (C) 2012 Erik van Wijk (http://mbed.org/users/evwijk/) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + #include "ButtonIn.h" ButtonIn::ButtonIn(PinName buttonPin) : @@ -6,6 +25,7 @@ _callback = NULL; _callbackInstance = NULL; _callbackMethod = NULL; + timeout = 200; _button.rise(this, &ButtonIn::click); } @@ -20,18 +40,14 @@ } void ButtonIn::click() { - printf("click\r\n"); if (_buttonCanPress) { _buttonCanPress = false; - printf("press\r\n"); - //_buttonDownTimer.reset(); - _buttonDownTimeout.attach(this, &ButtonIn::reset, 5); + _buttonDownTimeout.attach_us(this, &ButtonIn::reset, timeout * 1000); call(); } } void ButtonIn::call() { - printf("call\r\n"); if (_callback != NULL) (*_callback)(); else