diff options
author | Vasil Zlatanov <v@skozl.com> | 2017-05-03 22:48:25 +0100 |
---|---|---|
committer | Vasil Zlatanov <v@skozl.com> | 2017-05-03 22:48:25 +0100 |
commit | ed42bbde1941d4121a1095d35e056a1c33cd0775 (patch) | |
tree | e234d85482585d4d57db8545f2c0a3dc143ddd66 /src | |
parent | a6ed1742539c62186fb903017b52dd48f145ae4f (diff) | |
download | e2-switch-ed42bbde1941d4121a1095d35e056a1c33cd0775.tar.gz e2-switch-ed42bbde1941d4121a1095d35e056a1c33cd0775.tar.bz2 e2-switch-ed42bbde1941d4121a1095d35e056a1c33cd0775.zip |
Add counter class for inputs.
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; +}; |