Kevin Sullivan
/
summerlab2020q2_1
lab
Revision 2:cc5021b73dc1, committed 2020-07-31
- Comitter:
- kevinsullivan
- Date:
- Fri Jul 31 20:18:44 2020 +0000
- Parent:
- 1:2e8c02d29418
- Commit message:
- lab q2_1
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 2e8c02d29418 -r cc5021b73dc1 main.cpp --- a/main.cpp Sun Jul 19 19:46:59 2020 +0000 +++ b/main.cpp Fri Jul 31 20:18:44 2020 +0000 @@ -1,20 +1,24 @@ #include "mbed.h" Serial pc(USBTX, USBRX); // tx, rx PwmOut led(LED1); -float brightness = 0.0; +float brightness = 0.0; //brightness is a variable of type float(a real number) + int main() { - 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; + pc.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down\n\r");//once off printf message + pc.printf(" '^' is printed each time up is selected\n\r");//once off printf message + pc.printf(" '<' is printed each time down is selected\n\r");//once off printf message + while(1) { // "do forever" while true i.e. (1) + char c = pc.getc(); //defines a variable c of type char and sets it to character recieved from Tera Term + if((c == 'u') && (brightness < 0.5)) { // is c=u, and (bool AND) less than half the brightness + brightness += 0.01; // brightness = brightness + 0.01 led = brightness; pc.putc('^');// using "^" for LED brightness up + } - if((c == 'd') & (brightness > 0.0)) { - brightness -= 0.01; + if((c == 'd') && (brightness > 0.0)) { + brightness -= 0.01;//brightness = brightness - 0.01 led = brightness; - pc.putc('~');//using " ~ " for down LED brightness down + pc.putc('<');//using " < " for down LED brightness down } } } \ No newline at end of file