From ed42bbde1941d4121a1095d35e056a1c33cd0775 Mon Sep 17 00:00:00 2001 From: Vasil Zlatanov Date: Wed, 3 May 2017 22:48:25 +0100 Subject: Add counter class for inputs. --- src/counter.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/counter.h 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; +}; -- cgit v1.2.3