![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
2.1 Serialcommunication Lab work
main.cpp@0:18163e435f7c, 2020-06-25 (annotated)
- Committer:
- tonyk37
- Date:
- Thu Jun 25 07:43:43 2020 +0000
- Revision:
- 0:18163e435f7c
Rev A June 25
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tonyk37 | 0:18163e435f7c | 1 | #include "mbed.h" |
tonyk37 | 0:18163e435f7c | 2 | |
tonyk37 | 0:18163e435f7c | 3 | Serial pc(USBTX, USBRX); // tx, rx |
tonyk37 | 0:18163e435f7c | 4 | PwmOut led(LED1); |
tonyk37 | 0:18163e435f7c | 5 | |
tonyk37 | 0:18163e435f7c | 6 | float brightness = 0.0; |
tonyk37 | 0:18163e435f7c | 7 | |
tonyk37 | 0:18163e435f7c | 8 | int main() { |
tonyk37 | 0:18163e435f7c | 9 | pc.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down\n"); |
tonyk37 | 0:18163e435f7c | 10 | |
tonyk37 | 0:18163e435f7c | 11 | while(1) { |
tonyk37 | 0:18163e435f7c | 12 | char c = pc.getc(); |
tonyk37 | 0:18163e435f7c | 13 | if((c =='u') && (brightness < 0.5)) { |
tonyk37 | 0:18163e435f7c | 14 | brightness += 0.01; |
tonyk37 | 0:18163e435f7c | 15 | led = brightness; |
tonyk37 | 0:18163e435f7c | 16 | pc.putc('>'); |
tonyk37 | 0:18163e435f7c | 17 | } |
tonyk37 | 0:18163e435f7c | 18 | if((c =='d') && (brightness > 0.0)) { |
tonyk37 | 0:18163e435f7c | 19 | brightness -= 0.01; |
tonyk37 | 0:18163e435f7c | 20 | led = brightness; |
tonyk37 | 0:18163e435f7c | 21 | pc.putc('<'); |
tonyk37 | 0:18163e435f7c | 22 | } |
tonyk37 | 0:18163e435f7c | 23 | } |
tonyk37 | 0:18163e435f7c | 24 | } |