Serial

Dependencies:   mbed

Revision:
0:645979190d77
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Nov 15 17:24:05 2018 +0000
@@ -0,0 +1,57 @@
+#include "mbed.h"
+ 
+ 
+ class SerialEvent
+ {
+    private:
+     Serial _isr;                       // für serielles einlesen
+     volatile int16_t _pressed;    // wegen multicore unterstützung
+     void _risingISR();             // prototyping
+     char _str;                      // str ist nur eine Variable, könnte auch zeichen heißen
+     
+    public:
+     int checkFlag();
+     void read(char& zeichen);
+     SerialEvent(PinName tx, PinName rx): _isr(tx,rx)       //Konstruktor
+     {
+         _isr.attach(callback(this, &SerialEvent::_risingISR));
+     }
+    };
+      
+     void SerialEvent :: read(char& 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;
+     if( pc.checkFlag())
+     pc.read(z);
+     printf("Zeichen: %c",z);
+     
+     }
\ No newline at end of file