Example code for 'Mechatronics Class'

Revision:
0:8c7b073576c5
Child:
2:83a817de162e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jan 19 14:21:47 2017 -0600
@@ -0,0 +1,29 @@
+#include "mbed.h"
+
+class Counter {
+public:
+    Counter(PinName pin) : _interrupt(pin) {        // create the InterruptIn on the pin specified to Counter
+        _interrupt.rise(callback(this, &Counter::increment)); // attach increment function of this counter instance
+    }
+
+    void increment() {
+        _count++;
+    }
+
+    int read() {
+        return _count;
+    }
+
+private:
+    InterruptIn _interrupt;
+    volatile int _count;
+};
+
+Counter counter(SW2);
+
+int main() {
+    while(1) {
+        printf("Count so far: %d\n", counter.read());
+        wait(2);
+    }
+}
\ No newline at end of file