Klassen

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
corsa1600
Date:
Mon Feb 04 17:01:00 2019 +0000
Commit message:
Klassen

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Feb 04 17:01:00 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187
\ No newline at end of file