summaryrefslogtreecommitdiff
path: root/src/counter.h
blob: 978974d9ab22a6345be42acdeb3391840b94ea9f (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
#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;
    }

    int write(int new_count) {
        _count = new_count;
    }
 
private:
    InterruptIn _interrupt;
    volatile int _count;
};