Provides an extended version of DigitalOut that adds a "toggle()" function, and uses the RTOS Thread API to provide a "flash()" function that toggles the pin in the background at a given interval.
Example of use:
#include "mbed.h" #include "rtos.h" /* NOTE: Requires the RTOS library or a matching API */ #include "DigitalOutEx.h" DigitalOutEx led1(LED1); DigitalOutEx led2(LED2); int main() { led1.flash(200); led2.flash(500); Thread::wait(5000); led1.flash(50); Thread::wait(5000); led1 = 0; Thread::wait(5000); led1.flash(1000); while (1) { } }
Revision 1:6f8ca7b70778, committed 2013-04-26
- Comitter:
- Byrn
- Date:
- Fri Apr 26 11:31:13 2013 +0000
- Parent:
- 0:1798e1bf583a
- Commit message:
- Fixed a memory leak (I am an idiot).
Changed in this revision
DigitalOutEx.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 1798e1bf583a -r 6f8ca7b70778 DigitalOutEx.cpp --- a/DigitalOutEx.cpp Fri Apr 26 10:31:31 2013 +0000 +++ b/DigitalOutEx.cpp Fri Apr 26 11:31:13 2013 +0000 @@ -25,8 +25,11 @@ void DigitalOutEx::stop_flashing() { if (!_flashing) return; - _flashThread->terminate(); - _flashThread = NULL; + if (_flashThread != NULL) { + _flashThread->terminate(); + delete _flashThread; + _flashThread = NULL; + } _flashing = 0; }