Serial_communications

Dependencies:   mbed

main.cpp

Committer:
jforde
Date:
2020-07-28
Revision:
2:48b09c6b3262
Parent:
0:fb6bbc10ffa0

File content as of revision 2:48b09c6b3262:

#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) {
        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;
        }
    }
}