Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@0:01efb7ad1c3e, 2021-12-21 (annotated)
- Committer:
- t00221592
- Date:
- Tue Dec 21 10:01:36 2021 +0000
- Revision:
- 0:01efb7ad1c3e
T00221592 Instrumentation Winter Lab
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| t00221592 | 0:01efb7ad1c3e | 1 | #include "mbed.h" |
| t00221592 | 0:01efb7ad1c3e | 2 | Serial pc(USBTX, USBRX); // tx, rx |
| t00221592 | 0:01efb7ad1c3e | 3 | PwmOut led(LED1); |
| t00221592 | 0:01efb7ad1c3e | 4 | float brightness = 0.0; |
| t00221592 | 0:01efb7ad1c3e | 5 | int main() { |
| t00221592 | 0:01efb7ad1c3e | 6 | pc.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down\n"); |
| t00221592 | 0:01efb7ad1c3e | 7 | while(1) { |
| t00221592 | 0:01efb7ad1c3e | 8 | char c = pc.getc(); |
| t00221592 | 0:01efb7ad1c3e | 9 | if((c == 'u') && (brightness < 0.5)) { |
| t00221592 | 0:01efb7ad1c3e | 10 | brightness += 0.01; |
| t00221592 | 0:01efb7ad1c3e | 11 | led = brightness; |
| t00221592 | 0:01efb7ad1c3e | 12 | pc.printf("^"); |
| t00221592 | 0:01efb7ad1c3e | 13 | } |
| t00221592 | 0:01efb7ad1c3e | 14 | if((c == 'd') && (brightness > 0.0)) { |
| t00221592 | 0:01efb7ad1c3e | 15 | brightness -= 0.01; |
| t00221592 | 0:01efb7ad1c3e | 16 | led = brightness; |
| t00221592 | 0:01efb7ad1c3e | 17 | pc.printf("v"); |
| t00221592 | 0:01efb7ad1c3e | 18 | } |
| t00221592 | 0:01efb7ad1c3e | 19 | } |
| t00221592 | 0:01efb7ad1c3e | 20 | } |