A slightly more advanced blinky demo
Dependencies: mbed
BetterBlink.cpp@0:e71f2de5726c, 2014-06-13 (annotated)
- Committer:
- ethanharstad
- Date:
- Fri Jun 13 18:58:36 2014 +0000
- Revision:
- 0:e71f2de5726c
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ethanharstad | 0:e71f2de5726c | 1 | #include "mbed.h" |
ethanharstad | 0:e71f2de5726c | 2 | |
ethanharstad | 0:e71f2de5726c | 3 | DigitalOut out(LED1); |
ethanharstad | 0:e71f2de5726c | 4 | DigitalIn in(USER_BUTTON); |
ethanharstad | 0:e71f2de5726c | 5 | |
ethanharstad | 0:e71f2de5726c | 6 | int divisor = 1; |
ethanharstad | 0:e71f2de5726c | 7 | |
ethanharstad | 0:e71f2de5726c | 8 | int main() { |
ethanharstad | 0:e71f2de5726c | 9 | while(true) { |
ethanharstad | 0:e71f2de5726c | 10 | if(in == false) { |
ethanharstad | 0:e71f2de5726c | 11 | divisor *= 2; |
ethanharstad | 0:e71f2de5726c | 12 | if(divisor >= 16) divisor = 1; |
ethanharstad | 0:e71f2de5726c | 13 | } |
ethanharstad | 0:e71f2de5726c | 14 | out = 1; |
ethanharstad | 0:e71f2de5726c | 15 | wait_ms(500 / divisor); |
ethanharstad | 0:e71f2de5726c | 16 | out = 0; |
ethanharstad | 0:e71f2de5726c | 17 | wait_ms(500 / divisor); |
ethanharstad | 0:e71f2de5726c | 18 | } |
ethanharstad | 0:e71f2de5726c | 19 | } |