Serial Passthporuogh

Dependencies:   mbed

Revision:
2:357688b9dfe9
Parent:
1:e9d1c42a73ae
diff -r e9d1c42a73ae -r 357688b9dfe9 main.cpp
--- a/main.cpp	Fri Feb 28 06:52:34 2014 +0000
+++ b/main.cpp	Tue Dec 29 13:17:51 2015 +0000
@@ -1,21 +1,40 @@
 #include "mbed.h"
 
-//------------------------------------
-// Hyperterminal configuration
-// 9600 bauds, 8-bit data, no parity
-//------------------------------------
-
 Serial pc(SERIAL_TX, SERIAL_RX);
- 
-DigitalOut myled(LED1);
- 
-int main() {
-  int i = 1;
-  pc.printf("Hello World !\n");
-  while(1) { 
-      wait(1);
-      pc.printf("This program runs since %d seconds.\n", i++);
-      myled = !myled;
-  }
+Serial device(PA_9, PA_10);  // tx, rx
+
+void callbackPC()
+{
+    while(pc.readable()) {
+        device.putc(pc.getc());
+    }
+}
+
+void callbackDEVICE()
+{
+    while(device.readable()) {
+        pc.putc(device.getc());
+    }
 }
- 
\ No newline at end of file
+
+void setup()
+{
+    pc.printf("Setting up Setup...");
+    pc.baud(115200);
+    pc.attach(&callbackPC);
+    device.baud(115200);
+    device.attach(&callbackDEVICE);
+}
+DigitalIn btn1(PC_13);
+DigitalOut myled(PA_5);
+int main()
+{
+    setup();
+    while(1) {
+        if(btn1) {
+            myled=1;
+        } else {
+            myled=0;
+        }
+    }
+}