diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/counter.h | 20 | 
1 files changed, 20 insertions, 0 deletions
| diff --git a/src/counter.h b/src/counter.h new file mode 100644 index 0000000..e0126db --- /dev/null +++ b/src/counter.h @@ -0,0 +1,20 @@ +#include "mbed.h" + +class Counter { +public: +    Counter(PinName pin) : _interrupt(pin) {        // create the InterruptIn on the pin specified to Counter +        _interrupt.rise(this, &Counter::increment); // attach increment function of this counter instance +    } +  +    void increment() { +        _count++; +    } +  +    int read() { +        return _count; +    } +  +private: +    InterruptIn _interrupt; +    volatile int _count; +}; | 
