Klassen

Dependencies:   mbed

Revision:
0:66758402f28d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Feb 04 17:01:00 2019 +0000
@@ -0,0 +1,63 @@
+#include "mbed.h"
+ 
+class SwEvent
+{
+ 
+public:
+    SwEvent (PinName pin) : _pressed(pin)
+    {
+        _pressed.rise(callback(this, &SwEvent::checkFlag)); // attach increment function of this counter instance
+    }
+    void checkFlag()
+    {
+       _checkFlag = !_checkFlag ;
+    }
+
+
+
+    bool read() 
+    {
+        return _checkFlag;
+    }
+
+private:
+
+    InterruptIn _pressed;
+    volatile bool _checkFlag;
+ 
+};
+ 
+ 
+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(p14);
+SwEvent swevent (p15);
+ 
+int main() {
+    while(1) {
+        printf("Count so far: %d\n", counter.read());
+        printf("true/false so far: %d\n", swevent.read());
+        wait(2);
+    }
+}
\ No newline at end of file