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

Dependencies:   mbed

Fork of FRDM_serial_echo_demo by felipe manrique

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002  
00003 Serial pc(USBTX, USBRX); // tx, rx
00004 PwmOut led(LED1);
00005  
00006 float brightness = 0.0;
00007  
00008 int main() {
00009     pc.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down\n");
00010  
00011     while(1) {
00012         char c = pc.getc();
00013         if((c == 'u') && (brightness < 0.5)) {
00014             brightness += 0.01;
00015             led = brightness;
00016         }
00017         if((c == 'd') && (brightness > 0.0)) {
00018             brightness -= 0.01;
00019             led = brightness;
00020         } 
00021  
00022     }
00023 }