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:486592635dfd, 2010-07-04 (annotated)
- Committer:
- gadgetcafe08
- Date:
- Sun Jul 04 06:19:34 2010 +0000
- Revision:
- 1:486592635dfd
- Parent:
- 0:c058fc45eb34
- Child:
- 2:b26dd68e6a19
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| gadgetcafe08 | 0:c058fc45eb34 | 1 | #include "mbed.h" |
| gadgetcafe08 | 0:c058fc45eb34 | 2 | |
| gadgetcafe08 | 1:486592635dfd | 3 | DigitalIn sw(p5); |
| gadgetcafe08 | 0:c058fc45eb34 | 4 | DigitalOut myled1(LED1); |
| gadgetcafe08 | 0:c058fc45eb34 | 5 | DigitalOut myled2(LED2); |
| gadgetcafe08 | 0:c058fc45eb34 | 6 | DigitalOut myled3(LED3); |
| gadgetcafe08 | 0:c058fc45eb34 | 7 | DigitalOut myled4(LED4); |
| gadgetcafe08 | 1:486592635dfd | 8 | DigitalOut leds[] = {myled1, myled2, myled3, myled4}; |
| gadgetcafe08 | 0:c058fc45eb34 | 9 | |
| gadgetcafe08 | 0:c058fc45eb34 | 10 | int timeBase = 0; |
| gadgetcafe08 | 1:486592635dfd | 11 | int ledPx = 0; |
| gadgetcafe08 | 0:c058fc45eb34 | 12 | |
| gadgetcafe08 | 0:c058fc45eb34 | 13 | void tick() { |
| gadgetcafe08 | 0:c058fc45eb34 | 14 | if ((timeBase += 1) == 10) { |
| gadgetcafe08 | 0:c058fc45eb34 | 15 | timeBase = 0; |
| gadgetcafe08 | 0:c058fc45eb34 | 16 | } |
| gadgetcafe08 | 0:c058fc45eb34 | 17 | } |
| gadgetcafe08 | 0:c058fc45eb34 | 18 | |
| gadgetcafe08 | 1:486592635dfd | 19 | void countupLed() { |
| gadgetcafe08 | 1:486592635dfd | 20 | if (sw == 0) { |
| gadgetcafe08 | 1:486592635dfd | 21 | ledPx++; |
| gadgetcafe08 | 1:486592635dfd | 22 | if (ledPx == 4) { |
| gadgetcafe08 | 1:486592635dfd | 23 | ledPx = 0; |
| gadgetcafe08 | 1:486592635dfd | 24 | } |
| gadgetcafe08 | 1:486592635dfd | 25 | } else { |
| gadgetcafe08 | 1:486592635dfd | 26 | ledPx--; |
| gadgetcafe08 | 1:486592635dfd | 27 | if (ledPx == -1) { |
| gadgetcafe08 | 1:486592635dfd | 28 | ledPx = 4; |
| gadgetcafe08 | 1:486592635dfd | 29 | } |
| gadgetcafe08 | 1:486592635dfd | 30 | } |
| gadgetcafe08 | 1:486592635dfd | 31 | } |
| gadgetcafe08 | 1:486592635dfd | 32 | |
| gadgetcafe08 | 0:c058fc45eb34 | 33 | void blink(DigitalOut *led, int timing) { |
| gadgetcafe08 | 0:c058fc45eb34 | 34 | if ((timeBase % timing) == 0) { |
| gadgetcafe08 | 0:c058fc45eb34 | 35 | if (led->read() == 0) { |
| gadgetcafe08 | 0:c058fc45eb34 | 36 | led->write(1); |
| gadgetcafe08 | 0:c058fc45eb34 | 37 | } else { |
| gadgetcafe08 | 0:c058fc45eb34 | 38 | led->write(0); |
| gadgetcafe08 | 0:c058fc45eb34 | 39 | } |
| gadgetcafe08 | 0:c058fc45eb34 | 40 | } |
| gadgetcafe08 | 0:c058fc45eb34 | 41 | } |
| gadgetcafe08 | 0:c058fc45eb34 | 42 | |
| gadgetcafe08 | 0:c058fc45eb34 | 43 | int main() { |
| gadgetcafe08 | 0:c058fc45eb34 | 44 | while(1) { |
| gadgetcafe08 | 1:486592635dfd | 45 | blink(&leds[ledPx], 1); |
| gadgetcafe08 | 1:486592635dfd | 46 | countupLed(); |
| gadgetcafe08 | 0:c058fc45eb34 | 47 | tick(); |
| gadgetcafe08 | 0:c058fc45eb34 | 48 | wait(0.1); |
| gadgetcafe08 | 0:c058fc45eb34 | 49 | } |
| gadgetcafe08 | 0:c058fc45eb34 | 50 | } |