Serial_communications

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
jforde
Date:
Tue Jul 28 11:39:25 2020 +0000
Parent:
1:03c191369089
Commit message:
Serial_Com;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Jan 01 20:57:57 2012 +0000
+++ b/main.cpp	Tue Jul 28 11:39:25 2020 +0000
@@ -1,12 +1,19 @@
-#include "mbed.h"
-
-DigitalOut myled(LED1);
-
-int main() {
+#include "mbed.h"                       //Preprocessor Directives 
+                                        // Declarations 
+Serial pc(USBTX, USBRX); // tx, rx
+PwmOut led(LED1);
+float brightness = 0.0;
+int main() {                                      //instructions in main () function 
+    pc.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down\n");
     while(1) {
-        myled = 1;
-        wait(0.2);
-        myled = 0;
-        wait(0.2);
+        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