Joseph Forde
/
JF_Serial_communications
Serial_communications
Diff: main.cpp
- Revision:
- 2:48b09c6b3262
- Parent:
- 0:fb6bbc10ffa0
--- 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