Joseph Forde
/
JF_Serial_communications_1
Serial_communications_1
main.cpp
- Committer:
- jforde
- Date:
- 2020-07-28
- Revision:
- 4:eabf5656c755
- Parent:
- 3:4e35f0d99e64
File content as of revision 4:eabf5656c755:
#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(); //Reads a character from keyboard if((c == 'u') && (brightness < 0.5)) { brightness += 0.01; led = brightness; pc.putc('^'); // Writes a character ('^') to the standard output } if((c == 'd') && (brightness > 0.0)) { brightness -= 0.01; led = brightness; pc.putc('v'); // Writes a character ('v') to the standard output } } }