Serial communication program

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
T00209563
Date:
Sat Aug 01 15:37:18 2020 +0000
Commit message:
Serial communication program to terra term

Changed in this revision

Serial.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/Serial.cpp	Sat Aug 01 15:37:18 2020 +0000
@@ -0,0 +1,27 @@
+#include "mbed.h"
+
+Serial pc(USBTX,USBRX);   //defines an object called pc of serial class, and points it at the usb port
+PwmOut led(LED1);        //pulse width modulation
+float brightness = 0.0; //brightness ia a variable of type float
+
+
+int main()
+{
+    pc.printf ("Press 'u' = brighter, 'd' = dimmer\n\r"); //outputs a message at the start
+
+    while(1) {
+
+        char c = pc.getc ();
+        if (( c =='u') && (brightness < 0.5)) {
+            brightness += 0.01;
+            pc.putc('^');   // when U is pressed ^ is printed to the screen
+            led = brightness;
+        }
+        if (( c =='d') && (brightness > 0.0)) {
+            brightness -= 0.01;
+            pc.putc('V');   // when d is pressed V is printed to the screen
+            led = brightness;
+        }
+
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Aug 01 15:37:18 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file