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.
Revision 1:486592635dfd, committed 2010-07-04
- Comitter:
- gadgetcafe08
- Date:
- Sun Jul 04 06:19:34 2010 +0000
- Parent:
- 0:c058fc45eb34
- Child:
- 2:b26dd68e6a19
- Commit message:
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Jul 04 05:51:22 2010 +0000
+++ b/main.cpp Sun Jul 04 06:19:34 2010 +0000
@@ -1,11 +1,14 @@
#include "mbed.h"
+DigitalIn sw(p5);
DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);
+DigitalOut leds[] = {myled1, myled2, myled3, myled4};
int timeBase = 0;
+int ledPx = 0;
void tick() {
if ((timeBase += 1) == 10) {
@@ -13,6 +16,20 @@
}
}
+void countupLed() {
+ if (sw == 0) {
+ ledPx++;
+ if (ledPx == 4) {
+ ledPx = 0;
+ }
+ } else {
+ ledPx--;
+ if (ledPx == -1) {
+ ledPx = 4;
+ }
+ }
+}
+
void blink(DigitalOut *led, int timing) {
if ((timeBase % timing) == 0) {
if (led->read() == 0) {
@@ -25,10 +42,8 @@
int main() {
while(1) {
- blink(&myled1, 1);
- blink(&myled2, 2);
- blink(&myled3, 3);
- blink(&myled4, 4);
+ blink(&leds[ledPx], 1);
+ countupLed();
tick();
wait(0.1);
}