![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
lab
main.cpp@2:cc5021b73dc1, 2020-07-31 (annotated)
- Committer:
- kevinsullivan
- Date:
- Fri Jul 31 20:18:44 2020 +0000
- Revision:
- 2:cc5021b73dc1
- Parent:
- 1:2e8c02d29418
lab q2_1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kevinsullivan | 0:94dcb8c6ed26 | 1 | #include "mbed.h" |
kevinsullivan | 0:94dcb8c6ed26 | 2 | Serial pc(USBTX, USBRX); // tx, rx |
kevinsullivan | 0:94dcb8c6ed26 | 3 | PwmOut led(LED1); |
kevinsullivan | 2:cc5021b73dc1 | 4 | float brightness = 0.0; //brightness is a variable of type float(a real number) |
kevinsullivan | 2:cc5021b73dc1 | 5 | |
kevinsullivan | 0:94dcb8c6ed26 | 6 | int main() { |
kevinsullivan | 2:cc5021b73dc1 | 7 | pc.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down\n\r");//once off printf message |
kevinsullivan | 2:cc5021b73dc1 | 8 | pc.printf(" '^' is printed each time up is selected\n\r");//once off printf message |
kevinsullivan | 2:cc5021b73dc1 | 9 | pc.printf(" '<' is printed each time down is selected\n\r");//once off printf message |
kevinsullivan | 2:cc5021b73dc1 | 10 | while(1) { // "do forever" while true i.e. (1) |
kevinsullivan | 2:cc5021b73dc1 | 11 | char c = pc.getc(); //defines a variable c of type char and sets it to character recieved from Tera Term |
kevinsullivan | 2:cc5021b73dc1 | 12 | if((c == 'u') && (brightness < 0.5)) { // is c=u, and (bool AND) less than half the brightness |
kevinsullivan | 2:cc5021b73dc1 | 13 | brightness += 0.01; // brightness = brightness + 0.01 |
kevinsullivan | 0:94dcb8c6ed26 | 14 | led = brightness; |
kevinsullivan | 1:2e8c02d29418 | 15 | pc.putc('^');// using "^" for LED brightness up |
kevinsullivan | 2:cc5021b73dc1 | 16 | |
kevinsullivan | 0:94dcb8c6ed26 | 17 | } |
kevinsullivan | 2:cc5021b73dc1 | 18 | if((c == 'd') && (brightness > 0.0)) { |
kevinsullivan | 2:cc5021b73dc1 | 19 | brightness -= 0.01;//brightness = brightness - 0.01 |
kevinsullivan | 0:94dcb8c6ed26 | 20 | led = brightness; |
kevinsullivan | 2:cc5021b73dc1 | 21 | pc.putc('<');//using " < " for down LED brightness down |
kevinsullivan | 0:94dcb8c6ed26 | 22 | } |
kevinsullivan | 0:94dcb8c6ed26 | 23 | } |
kevinsullivan | 0:94dcb8c6ed26 | 24 | } |