Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Revision 0:82fe2f4476f9, committed 2019-01-31
- Comitter:
- Powers
- Date:
- Thu Jan 31 22:07:53 2019 +0000
- Commit message:
- Uebung mit serieller Schnittstelle; RX - Interrupt
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 Thu Jan 31 22:07:53 2019 +0000
@@ -0,0 +1,72 @@
+#include "mbed.h"
+
+// Uebung mit serieller Schnittstelle und Interrupts
+// Ausgabe - SERIAL
+// Programm wartet auf eine Eingabe, der String wird dann jeweils um
+// die Eingabe erweitert
+// RESET durch Eingabe von '.' [PUNKT]
+
+
+class SerialEvent
+{
+private:
+ Serial _connection;
+ bool _flag;
+ int _x;
+
+public:
+ SerialEvent(PinName tx, PinName rx): _connection(tx, rx) // Construktor
+ {
+ _connection.attach(callback(this, &SerialEvent::readSerial));
+ }
+
+ char content[200];
+
+ void readSerial(void);
+ bool checkFlag(void);
+};
+
+
+void SerialEvent::readSerial(void)
+{
+ if (_connection.readable()) content[_x] = _connection.getc();
+
+ if (content[_x] == '.')
+ {
+ content[_x] = '\0';
+ _x = 0;
+ _flag = 0;
+
+
+ int y = 0;
+ while(content[y] != '\0')
+ {
+ content[y] = '\0';
+ y++;
+ }
+ y = 0;
+ }
+ else
+ {
+ _x++;
+ _flag = 1;
+ }
+
+}
+
+bool SerialEvent::checkFlag(void)
+{
+ return _flag;
+}
+
+SerialEvent connectme(USBTX, USBRX); // Neues Objekt erstellen und übergabe von TX und RX
+
+int main()
+{
+ // Ausgabe des momentanen Status sowie dem attachten String
+ while(1)
+ {
+ printf("Flag Status: %i String: %s \n", connectme.checkFlag(), connectme.content);
+ wait_ms(200);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Jan 31 22:07:53 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187 \ No newline at end of file