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 0:b3b916d72b56, committed 2009-11-26
- Comitter:
- sknop
- Date:
- Thu Nov 26 11:05:33 2009 +0000
- Commit message:
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r b3b916d72b56 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Nov 26 11:05:33 2009 +0000
@@ -0,0 +1,80 @@
+#include "mbed.h"
+
+DigitalOut myled1(LED1);
+DigitalOut myled2(LED2);
+DigitalOut myled3(LED3);
+DigitalOut myled4(LED4);
+
+DigitalOut * leds[4];
+
+class Dimmer {
+public:
+ Dimmer() {
+ counter = 0;
+ level = 0;
+ which = 0;
+ }
+
+ void led_dim() {
+ *(leds[which]) = ( counter <= level ) ? 1 : 0;
+
+ counter++;
+ if( counter > 100 ) {
+ counter = 0;
+ }
+ }
+
+ void setLevel(int l) { level = l; }
+ void setWhich(int w) { which = w; }
+
+private:
+ int counter;
+ int level;
+ int which;
+};
+
+int main() {
+ leds[0] = &myled1;
+ leds[1] = &myled2;
+ leds[2] = &myled3;
+ leds[3] = &myled4;
+
+ int level = 0;
+ int increment = 1;
+ int which = 0;
+
+ Dimmer dimmer;
+ Ticker timer;
+
+ timer.attach_us(&dimmer, &Dimmer::led_dim, 20);
+
+ while(1) {
+ level += increment;
+
+ if( level >= 100 ) {
+ which++;
+ if( which > 3 ) {
+ which = 3;
+ increment = -1;
+ }
+ else {
+ level = 0;
+ }
+ dimmer.setWhich( which );
+ }
+ else if( level <= 0 ) {
+ which--;
+ if( which < 0 ) {
+ which = 0;
+ increment = 1;
+ }
+ else {
+ level = 100;
+ }
+ dimmer.setWhich( which );
+ }
+
+ dimmer.setLevel(level);
+ wait(0.01);
+ }
+}
diff -r 000000000000 -r b3b916d72b56 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Nov 26 11:05:33 2009 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/32af5db564d4