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

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