Serial_communications_1

Dependencies:   mbed

Committer:
jforde
Date:
Tue Jul 28 11:42:09 2020 +0000
Revision:
4:eabf5656c755
Parent:
3:4e35f0d99e64
Serial_communications_1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jforde 4:eabf5656c755 1 #include "mbed.h" //Preprocessor Directives
jforde 4:eabf5656c755 2 // Declarations
jforde 4:eabf5656c755 3 Serial pc(USBTX, USBRX); // tx, rx
jforde 4:eabf5656c755 4 PwmOut led(LED1);
simon 0:fb6bbc10ffa0 5
jforde 4:eabf5656c755 6 float brightness = 0.0;
jforde 4:eabf5656c755 7 int main() { //instructions in main () function
jforde 4:eabf5656c755 8 pc.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down\n");
jforde 4:eabf5656c755 9
simon 0:fb6bbc10ffa0 10 while(1) {
jforde 4:eabf5656c755 11 char c = pc.getc(); //Reads a character from keyboard
jforde 4:eabf5656c755 12 if((c == 'u') && (brightness < 0.5)) {
jforde 4:eabf5656c755 13 brightness += 0.01;
jforde 4:eabf5656c755 14 led = brightness;
jforde 4:eabf5656c755 15 pc.putc('^'); // Writes a character ('^') to the standard output
jforde 4:eabf5656c755 16 }
jforde 4:eabf5656c755 17 if((c == 'd') && (brightness > 0.0)) {
jforde 4:eabf5656c755 18 brightness -= 0.01;
jforde 4:eabf5656c755 19 led = brightness;
jforde 4:eabf5656c755 20 pc.putc('v'); // Writes a character ('v') to the standard output
jforde 4:eabf5656c755 21 }
simon 0:fb6bbc10ffa0 22 }
simon 0:fb6bbc10ffa0 23 }
jforde 4:eabf5656c755 24