serial dimmer demo using serial interface based on :https://mbed.org/handbook/SerialPC example with minor modifications

Dependencies:   mbed

main.cpp

Committer:
felipeM
Date:
2013-10-05
Revision:
0:623f6e1e1e89

File content as of revision 0:623f6e1e1e89:

#include "mbed.h"
 
Serial pc(USBTX, USBRX); // tx, rx
PwmOut r (LED_RED);
 
float brightness = 0.25;
 
int main() {
    
    r.period(0.001);
    
    pc.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down\n");
 
    while(1) {
        char c = pc.getc();
        if((c == 'd') && (brightness < 1)) {
            brightness += 0.01;
            r = brightness;
        }
        if((c == 'u') && (brightness > 0.0)) {
            brightness -= 0.01;
            r = brightness;
        } 
 
    }
}