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

Dependencies:   mbed

Fork of FRDM_serial_echo_demo by felipe manrique

main.cpp

Committer:
morgonXak
Date:
2014-04-27
Revision:
1:675b841fe7dc
Parent:
0:806d4eb73e1e

File content as of revision 1:675b841fe7dc:

#include "mbed.h"
 
Serial pc(USBTX, USBRX); // tx, rx
PwmOut led(LED1);
 
float brightness = 0.0;
 
int main() {
    pc.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down\n");
 
    while(1) {
        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;
        } 
 
    }
}