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@1:6c8d46a9c3c9, 2010-05-11 (annotated)
- Committer:
- leonous
- Date:
- Tue May 11 21:15:44 2010 +0000
- Revision:
- 1:6c8d46a9c3c9
- Parent:
- 0:adb9fcb3b1bb
- Child:
- 2:7cdadcca2c06
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| leonous | 0:adb9fcb3b1bb | 1 | #include "mbed.h" |
| leonous | 0:adb9fcb3b1bb | 2 | |
| leonous | 0:adb9fcb3b1bb | 3 | DigitalOut myled1(LED1); |
| leonous | 0:adb9fcb3b1bb | 4 | DigitalOut myled2(LED2); |
| leonous | 0:adb9fcb3b1bb | 5 | DigitalOut myled3(LED3); |
| leonous | 0:adb9fcb3b1bb | 6 | DigitalOut myled4(LED4); |
| leonous | 0:adb9fcb3b1bb | 7 | |
| leonous | 0:adb9fcb3b1bb | 8 | void update_leds (int myleds) |
| leonous | 0:adb9fcb3b1bb | 9 | { |
| leonous | 1:6c8d46a9c3c9 | 10 | // update the LEDs |
| leonous | 0:adb9fcb3b1bb | 11 | myled1 = myleds & 1; |
| leonous | 0:adb9fcb3b1bb | 12 | myled2 = (myleds & 2) >> 1; |
| leonous | 0:adb9fcb3b1bb | 13 | myled3 = (myleds & 4) >> 2; |
| leonous | 0:adb9fcb3b1bb | 14 | myled4 = (myleds & 8) >> 3; |
| leonous | 0:adb9fcb3b1bb | 15 | } |
| leonous | 0:adb9fcb3b1bb | 16 | |
| leonous | 0:adb9fcb3b1bb | 17 | int main() |
| leonous | 0:adb9fcb3b1bb | 18 | { |
| leonous | 1:6c8d46a9c3c9 | 19 | unsigned int count, count_up, speed_up = 0 ; |
| leonous | 1:6c8d46a9c3c9 | 20 | float count_interval = 1.0; |
| leonous | 1:6c8d46a9c3c9 | 21 | |
| leonous | 1:6c8d46a9c3c9 | 22 | count_up = ~ count_up; |
| leonous | 1:6c8d46a9c3c9 | 23 | |
| leonous | 0:adb9fcb3b1bb | 24 | while(1) |
| leonous | 0:adb9fcb3b1bb | 25 | { |
| leonous | 1:6c8d46a9c3c9 | 26 | // update LEDs with the current count value |
| leonous | 0:adb9fcb3b1bb | 27 | update_leds (count); |
| leonous | 1:6c8d46a9c3c9 | 28 | |
| leonous | 1:6c8d46a9c3c9 | 29 | // count up or down depending on the value of count_up |
| leonous | 1:6c8d46a9c3c9 | 30 | if (count_up) |
| leonous | 1:6c8d46a9c3c9 | 31 | count++; |
| leonous | 1:6c8d46a9c3c9 | 32 | else |
| leonous | 1:6c8d46a9c3c9 | 33 | count--; |
| leonous | 1:6c8d46a9c3c9 | 34 | |
| leonous | 1:6c8d46a9c3c9 | 35 | // interval to next count |
| leonous | 0:adb9fcb3b1bb | 36 | wait(count_interval); |
| leonous | 0:adb9fcb3b1bb | 37 | |
| leonous | 1:6c8d46a9c3c9 | 38 | // update the count interval when the LED count gets to 16 |
| leonous | 1:6c8d46a9c3c9 | 39 | // decrement the interval every 16 lots of counts |
| leonous | 1:6c8d46a9c3c9 | 40 | if (speed_up && count % 16 == 0) |
| leonous | 1:6c8d46a9c3c9 | 41 | count_interval /= 2; |
| leonous | 0:adb9fcb3b1bb | 42 | else if (count % 16 == 0) |
| leonous | 1:6c8d46a9c3c9 | 43 | count_interval *= 2; |
| leonous | 0:adb9fcb3b1bb | 44 | |
| leonous | 0:adb9fcb3b1bb | 45 | if (count % 256 == 0) |
| leonous | 1:6c8d46a9c3c9 | 46 | speed_up = ~ speed_up; |
| leonous | 1:6c8d46a9c3c9 | 47 | |
| leonous | 1:6c8d46a9c3c9 | 48 | // change the count direction every 32 lots of counts |
| leonous | 1:6c8d46a9c3c9 | 49 | if (count % 512 == 0) |
| leonous | 0:adb9fcb3b1bb | 50 | count_up = ~ count_up; |
| leonous | 1:6c8d46a9c3c9 | 51 | |
| leonous | 0:adb9fcb3b1bb | 52 | } |
| leonous | 0:adb9fcb3b1bb | 53 | } |