summaryrefslogtreecommitdiff
path: root/tmk_core/tool/mbed/mbed-sdk/libraries/tests/mbed/ticker_mfun/main.cpp
blob: 18f1bb51c1fa06a424371ee213adb30b668feb60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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);
}