Interrupt

Dependencies:   mbed

Revision:
0:1992191bb2b6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Feb 04 16:55:02 2019 +0000
@@ -0,0 +1,45 @@
+#include "mbed.h"
+ 
+DigitalOut led (LED1);
+ 
+ 
+class SwEvent
+{
+    private:
+        InterruptIn  _isr;
+        bool _check;
+    public:    
+        SwEvent(PinName isr):_isr(isr) 
+        {
+            _isr.rise(callback(this, &SwEvent::setFlag));    
+        }
+        
+        bool checkFlag(void);
+        void setFlag(void);
+};
+ 
+ 
+ 
+void SwEvent::setFlag(void)
+{
+    _check = !_check;
+}
+ 
+bool SwEvent::checkFlag(void)
+{
+    
+        if (_check == 0) led = 1;
+        else if (_check == 1) led = 0;  
+        
+        return _check;
+}
+ 
+SwEvent checker(p15);
+ 
+int main() {
+    while(1) {
+        checker.checkFlag();
+        printf("Aktueller Status: %d \n", checker.checkFlag());
+        wait_ms(10);
+    }
+}
\ No newline at end of file