summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasil Zlatanov <v@skozl.com>2017-05-06 19:10:56 +0100
committerVasil Zlatanov <v@skozl.com>2017-05-06 19:10:56 +0100
commit523f047b1b3c42b0aa40305291ca5d29a1b543f5 (patch)
tree5f99e83a0436c5375f5cf19bacf4ce82978f5613
parentbcf234f5883edb850d844ffceb9905c890d9498e (diff)
downloade2-switch-523f047b1b3c42b0aa40305291ca5d29a1b543f5.tar.gz
e2-switch-523f047b1b3c42b0aa40305291ca5d29a1b543f5.tar.bz2
e2-switch-523f047b1b3c42b0aa40305291ca5d29a1b543f5.zip
Seperate counter into propper code and head file
-rw-r--r--src/counter.cpp21
-rw-r--r--src/counter.h31
2 files changed, 34 insertions, 18 deletions
diff --git a/src/counter.cpp b/src/counter.cpp
new file mode 100644
index 0000000..89e597c
--- /dev/null
+++ b/src/counter.cpp
@@ -0,0 +1,21 @@
+#include "counter.h"
+
+Counter::Counter(PinName pin):_interrupt(pin)
+{
+ _interrupt.rise(this, &Counter::increment);
+}
+
+void Counter::increment()
+{
+ _count++;
+}
+
+int Counter::read()
+{
+ return _count;
+}
+
+void Counter::write(int new_count)
+{
+ _count = new_count;
+}
diff --git a/src/counter.h b/src/counter.h
index e47475e..cc3e2f4 100644
--- a/src/counter.h
+++ b/src/counter.h
@@ -1,24 +1,19 @@
-#include "mbed.h"
+#ifndef COUNTER_H
+#define COUNTER_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;
- }
+#include "mbed.h"
- void write(int new_count) {
- _count = new_count;
- }
-
+class Counter
+{
private:
InterruptIn _interrupt;
volatile int _count;
+
+public:
+ Counter(PinName pin);
+ void increment();
+ int read();
+ void write(int new_count);
};
+
+#endif