![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Increase or decrease LED brightness with keyboard via serial port.
main.cpp@0:f83df7d9548d, 2015-03-10 (annotated)
- Committer:
- mbedaddict
- Date:
- Tue Mar 10 08:59:45 2015 +0000
- Revision:
- 0:f83df7d9548d
Pwm in order to increase or decrease brightness with keyboard keys.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedaddict | 0:f83df7d9548d | 1 | #include "mbed.h" |
mbedaddict | 0:f83df7d9548d | 2 | |
mbedaddict | 0:f83df7d9548d | 3 | Serial pc(USBTX, USBRX); // tx, rx |
mbedaddict | 0:f83df7d9548d | 4 | PwmOut led(LED1); |
mbedaddict | 0:f83df7d9548d | 5 | |
mbedaddict | 0:f83df7d9548d | 6 | float brightness = 0.0; |
mbedaddict | 0:f83df7d9548d | 7 | |
mbedaddict | 0:f83df7d9548d | 8 | int main() |
mbedaddict | 0:f83df7d9548d | 9 | { |
mbedaddict | 0:f83df7d9548d | 10 | pc.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down\n"); |
mbedaddict | 0:f83df7d9548d | 11 | |
mbedaddict | 0:f83df7d9548d | 12 | while(1) { |
mbedaddict | 0:f83df7d9548d | 13 | char c = pc.getc(); |
mbedaddict | 0:f83df7d9548d | 14 | if((c == 'u') && (brightness < 0.5)) { |
mbedaddict | 0:f83df7d9548d | 15 | brightness += 0.01; |
mbedaddict | 0:f83df7d9548d | 16 | led = brightness; |
mbedaddict | 0:f83df7d9548d | 17 | } |
mbedaddict | 0:f83df7d9548d | 18 | if((c == 'd') && (brightness > 0.0)) { |
mbedaddict | 0:f83df7d9548d | 19 | brightness -= 0.01; |
mbedaddict | 0:f83df7d9548d | 20 | led = brightness; |
mbedaddict | 0:f83df7d9548d | 21 | } |
mbedaddict | 0:f83df7d9548d | 22 | |
mbedaddict | 0:f83df7d9548d | 23 | } |
mbedaddict | 0:f83df7d9548d | 24 | } |