Klassen

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
corsa1600
Date:
Mon Feb 04 17:00:11 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:00:11 2019 +0000
@@ -0,0 +1,127 @@
+#include "mbed.h"
+ 
+ 
+ class SerialEvent
+ {
+    private:
+     Serial _isr;                       // für serielles einlesen
+     volatile int16_t _pressed;    // wegen multicore unterstützung
+     void _risingISR();             // prototyping
+     string _str;                      // str ist nur eine Variable, könnte auch zeichen heißen
+     
+    public:
+     int checkFlag();
+     void read(string& zeichen);
+     
+     SerialEvent(PinName tx, PinName rx): _isr(tx,rx)       //Konstruktor
+     {
+         _isr.attach(callback(this, &SerialEvent::_risingISR));
+     }
+    };
+      
+     void SerialEvent :: read(string& zeichen)
+     {
+         zeichen= _str;
+     }
+        
+     
+     void SerialEvent :: _risingISR()
+     {
+         _str = _isr.getc();
+         _pressed=1;
+     }
+     
+     int SerialEvent :: checkFlag ()
+     {
+         if(_pressed)
+         {
+         _pressed=0;
+         return true;
+         }
+         else
+         return false;
+     }
+         
+         SerialEvent pc(USBTX, USBRX);  //pc ist wieder nur irgendeine Variable
+  
+  
+  
+  
+  main()
+  {
+     
+     char z;
+     while(1)
+     {
+     if( pc.checkFlag())
+     {
+     pc.read(z);
+     printf("Zeichen: %c\n",z);
+     }
+     }
+     
+     }   
+     
+     
+     
+     
+/*
+     
+     
+     public:
+        SerialEvent 
+            {
+                
+            }
+            
+    privat: 
+    {
+     
+     }
+     
+};
+// ---------------- Switch Event Class  --------------------------
+class SwEvent 
+{
+        InterruptIn _isr;
+        volatile int16_t _pressed;
+        void _risingISR();
+ 
+    public:
+        SwEvent(PinName pin) : _isr(pin) {          // create the InterruptIn on the pin specified to SwEvent
+            _isr.rise(callback(this, &SwEvent::_risingISR));  // attach ISR-function of this SwEvent instance 
+            _pressed=0; 
+        }
+        int checkFlag();                            // must in do-condition (while(true)-loop) continuously interrogated
+        void init();
+};
+// ---------------- Switch Event Class Methodes --------------------------
+int SwEvent::checkFlag() 
+{
+    if( _pressed ) 
+    {
+        _pressed = 0; 
+        return 1;
+    }
+    return 0;
+}
+ 
+void SwEvent::_risingISR() 
+{            
+    if( _isr.read() )
+        _pressed = 1;
+}
+};
+ 
+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:00:11 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187
\ No newline at end of file