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
- Committer:
- gadgetcafe08
- Date:
- 2010-07-04
- Revision:
- 1:486592635dfd
- Parent:
- 0:c058fc45eb34
- Child:
- 2:b26dd68e6a19
File content as of revision 1:486592635dfd:
#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) {
timeBase = 0;
}
}
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) {
led->write(1);
} else {
led->write(0);
}
}
}
int main() {
while(1) {
blink(&leds[ledPx], 1);
countupLed();
tick();
wait(0.1);
}
}