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 Servo SDFileSystem
Revision 3:ab9f94d112c0, committed 2015-08-08
- Comitter:
- taoqiuyang
- Date:
- Sat Aug 08 08:20:18 2015 +0000
- Parent:
- 2:afb333543af5
- Child:
- 4:37d118f2348c
- Commit message:
- read string using interrupt
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Aug 08 08:01:25 2015 +0000
+++ b/main.cpp Sat Aug 08 08:20:18 2015 +0000
@@ -1,5 +1,6 @@
#include "mbed.h"
-
+#include <string>
+
DigitalOut led1(LED1);
DigitalOut led2(LED2);
@@ -7,13 +8,36 @@
Serial IMU(p28, p27); // tx, rx
char IMU_message[256];
+int IMU_message_counter=0;
void callback() {
- // Note: you need to actually read from the serial to clear the RX interrupt
- pc.putc(IMU.getc());
+ char buf;
+
+ while (IMU.readable()) {
+ buf = IMU.getc();
+
+ IMU_message_counter+=1;
+ IMU_message[IMU_message_counter]=buf;
+
+ if (buf=='#'){
+ IMU_message_counter=0;
+ }
+
+ if (buf=='\n'){
+ int i;
+ for(i=0;i<=IMU_message_counter;i++){
+ pc.putc(IMU_message[i]);
+ }
+ }
+ }
+
+
led2 = !led2;
}
+
+
+
int main() {
IMU.baud(57600);
IMU.attach(&callback);