Simon Stillwell
/
BinaryLEDDisplay
Makes the 4 onboard LEDs count in binary
Diff: main.cpp
- Revision:
- 0:7d2043a942aa
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Sep 06 14:49:46 2010 +0000 @@ -0,0 +1,61 @@ +#include "mbed.h" + +// +//This is my first code for the Mbed. It's also my first c++ program. +//It is based on ABetterHelloWorld by Andrew Harpin +//The 4 LEDS on the Mbed repeatedly count in binary from 0 to 15 +// +// +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); +DigitalOut myled4(LED4); +Timer mytimer; + +int main() +{ + myled1 = 1; + myled2 = 1; + myled3 = 1; + myled4 = 1; + mytimer.start(); + + int intStart = mytimer.read_ms(); + int intCounter = 0; + bool blnSetalloff = true; + while(1) + { + if((mytimer.read_ms() - intStart) >= 250) + { + if (blnSetalloff) + { + myled1 = 0; + myled2 = 0; + myled3 = 0; + myled4 = 0; + blnSetalloff = false; + continue; + } + + if (intCounter % 16 > 7) + { + myled1 = 1; + } + if (intCounter % 8 > 3) + { + myled2 = 1; + } + if (intCounter % 4 > 1) + { + myled3 = 1; + } + if (intCounter % 2 == 1) + { + myled4 = 1; + } + intCounter +=1; + blnSetalloff = true; + intStart = mytimer.read_ms(); + } + } +} \ No newline at end of file