Serial_communications

Dependencies:   mbed

Committer:
jforde
Date:
Tue Jul 28 11:39:25 2020 +0000
Revision:
2:48b09c6b3262
Parent:
0:fb6bbc10ffa0
Serial_Com;

Who changed what in which revision?

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