Brian Moloney
/
Brian_Lab_Q_2_1
IT Tralee experiment
main.cpp@0:c6cc8dea2f4d, 2020-07-26 (annotated)
- Committer:
- bmol
- Date:
- Sun Jul 26 11:47:10 2020 +0000
- Revision:
- 0:c6cc8dea2f4d
- Child:
- 1:651ffd5a25c0
IT Tralee
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bmol | 0:c6cc8dea2f4d | 1 | #include "mbed.h" |
bmol | 0:c6cc8dea2f4d | 2 | Serial pc(USBTX, USBRX); // tx, rx |
bmol | 0:c6cc8dea2f4d | 3 | PwmOut led(LED1); |
bmol | 0:c6cc8dea2f4d | 4 | |
bmol | 0:c6cc8dea2f4d | 5 | float brightness = 0.0; |
bmol | 0:c6cc8dea2f4d | 6 | int main() |
bmol | 0:c6cc8dea2f4d | 7 | { |
bmol | 0:c6cc8dea2f4d | 8 | pc.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down\n"); |
bmol | 0:c6cc8dea2f4d | 9 | |
bmol | 0:c6cc8dea2f4d | 10 | while(1) { |
bmol | 0:c6cc8dea2f4d | 11 | char c = pc.getc(); |
bmol | 0:c6cc8dea2f4d | 12 | if((c == 'u') && (brightness < 0.5)) { |
bmol | 0:c6cc8dea2f4d | 13 | brightness += 0.01; |
bmol | 0:c6cc8dea2f4d | 14 | led = brightness; |
bmol | 0:c6cc8dea2f4d | 15 | pc.putc('^');//Extra code returns the character '^' on the pc interface |
bmol | 0:c6cc8dea2f4d | 16 | |
bmol | 0:c6cc8dea2f4d | 17 | } |
bmol | 0:c6cc8dea2f4d | 18 | |
bmol | 0:c6cc8dea2f4d | 19 | if((c == 'd') && (brightness > 0.0)) { |
bmol | 0:c6cc8dea2f4d | 20 | brightness -= 0.01; |
bmol | 0:c6cc8dea2f4d | 21 | led = brightness; |
bmol | 0:c6cc8dea2f4d | 22 | pc.putc('v');//Extra code returns the character 'v' on the pc interface |
bmol | 0:c6cc8dea2f4d | 23 | } |
bmol | 0:c6cc8dea2f4d | 24 | } |
bmol | 0:c6cc8dea2f4d | 25 | } |