Echo back characters you type based in https://mbed.org/handbook/SerialPC example

Dependencies:   mbed

Fork of FRDM_serial_echo_demo by felipe manrique

Files at this revision

API Documentation at this revision

Comitter:
morgonXak
Date:
Sun Apr 27 07:21:21 2014 +0000
Parent:
0:806d4eb73e1e
Commit message:
se

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 806d4eb73e1e -r 675b841fe7dc main.cpp
--- a/main.cpp	Sat Oct 05 19:10:27 2013 +0000
+++ b/main.cpp	Sun Apr 27 07:21:21 2014 +0000
@@ -1,10 +1,23 @@
-#include "mbed.h"              
+#include "mbed.h"
  
-Serial pc(USBTX, USBRX);
+Serial pc(USBTX, USBRX); // tx, rx
+PwmOut led(LED1);
+ 
+float brightness = 0.0;
  
 int main() {
-    pc.printf("Echoes back to the screen anything you type\n");
+    pc.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down\n");
+ 
     while(1) {
-        pc.putc(pc.getc());
+        char c = pc.getc();
+        if((c == 'u') && (brightness < 0.5)) {
+            brightness += 0.01;
+            led = brightness;
+        }
+        if((c == 'd') && (brightness > 0.0)) {
+            brightness -= 0.01;
+            led = brightness;
+        } 
+ 
     }
 }
\ No newline at end of file