summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVasil Zlatanov <v@skozl.com>2017-05-03 22:48:25 +0100
committerVasil Zlatanov <v@skozl.com>2017-05-03 22:48:25 +0100
commited42bbde1941d4121a1095d35e056a1c33cd0775 (patch)
treee234d85482585d4d57db8545f2c0a3dc143ddd66 /src
parenta6ed1742539c62186fb903017b52dd48f145ae4f (diff)
downloade2-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.h20
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;
+};