diff options
Diffstat (limited to 'tool/mbed/mbed-sdk/libraries/tests/mbed/ticker_mfun/main.cpp')
-rw-r--r-- | tool/mbed/mbed-sdk/libraries/tests/mbed/ticker_mfun/main.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tool/mbed/mbed-sdk/libraries/tests/mbed/ticker_mfun/main.cpp b/tool/mbed/mbed-sdk/libraries/tests/mbed/ticker_mfun/main.cpp new file mode 100644 index 0000000000..18f1bb51c1 --- /dev/null +++ b/tool/mbed/mbed-sdk/libraries/tests/mbed/ticker_mfun/main.cpp @@ -0,0 +1,41 @@ +#include "mbed.h" + +Ticker tick; +DigitalOut led(LED1); + +namespace { + const int MS_INTERVALS = 1000; +} + +class TickerHandler { +public: + TickerHandler(const int _ms_intervals) : m_ticker_count(0), m_ms_intervals(_ms_intervals) { + } + + void print_char(char c = '*') + { + printf("%c", c); + fflush(stdout); + } + + void togglePin(void) + { + if (ticker_count >= MS_INTERVALS) { + print_char(); + ticker_count = 0; + led = !led; // Blink + } + ticker_count++; + } + +protected: + int m_ticker_count; +}; + +int main() +{ + TickerHandler th; + + tick.attach_us(th, TickerHandler::togglePin, 1000); + while (1); +} |