
Serial communication program
Diff: Serial.cpp
- Revision:
- 0:2f8376278c8a
--- /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; + } + + } +}