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.
Diff: main.cpp
- Revision:
- 9:c3d4c7059979
- Parent:
- 8:77fd54b4864c
- Child:
- 11:b12ce020d1ba
- Child:
- 12:cce8984e5569
diff -r 77fd54b4864c -r c3d4c7059979 main.cpp --- a/main.cpp Sat Sep 21 20:49:33 2013 +0000 +++ b/main.cpp Sat Sep 21 21:26:02 2013 +0000 @@ -1,5 +1,6 @@ #include <queue> #include <algorithm> +#include <string> #include "mbed.h" @@ -347,7 +348,7 @@ virtual void Run() { supervisor.CurrentProgramDone(); - led2 = 1; + if (this == g_watchdog) led2 = 1; } } g_watchdog_impl; @@ -400,6 +401,88 @@ bool done_[6]; }; +class WalkingFade : public Schedulable +{ +public: + WalkingFade(int start_time, int led, int stride, int end, uint8_t a, uint8_t b, bool fast) + : led_(led), stride_(stride), end_(end), a_(a), b_(b), fast_(fast) { + time_ = start_time; + Schedule(this); + } + + virtual void Run() { + if (led_ >= end_ || led_ < 0) { + delete this; + return; + } + strip[led_] = getcolor(a_, b_); + led_ += stride_; + if (fast_) { + strip[led_] |= FAST; + time_ += 128; + } else { + time_ += 256; + } + strip_changed = true; + Schedule(this); + } + +private: + int led_, stride_, end_; + uint8_t a_,b_; + bool fast_, step_; +}; + + +class MorseGoogleProgram : public Schedulable { +public: + virtual void Run() { + const string code = "W.... .- .--. .--. -.-- / -... .. .-. - .... -.. .- -.-- --..-- / B--. R--- Y--- B--. G.-.. R. "; + const int kSpaceTime = 3*256; + const int kLedStart = 150; + const int kStride = -2; + const int kHalfStrideTime = 64; + const int kDotSpaceTime = 256; + int time = global_tick; + uint8_t color = WHITE; + for (int i = 0; i < code.size(); i++) { + switch (code[i]) { + case 'R': color = RED ; break; + case 'G': color = GREEN ; break; + case 'B': color = BLUE ; break; + case 'Y': color = YELLOW ; break; + case 'W': color = WHITE ; break; + case 'C': color = CYAN ; break; + case 'M': color = MAGENTA ; break; + case '.': { + new WalkingFade(time, kLedStart, kStride, 160, BLACK, color, true); time += kHalfStrideTime; + new WalkingFade(time, kLedStart - 1, kStride, 160, BLACK, color, true); time += kHalfStrideTime; + new WalkingFade(time, kLedStart, kStride, 160, color, BLACK, true); time += kHalfStrideTime; + new WalkingFade(time, kLedStart - 1, kStride, 160, color, BLACK, true); time += kHalfStrideTime; + time += kDotSpaceTime; + break; + } + case '-': { + new WalkingFade(time, kLedStart, kStride, 160, BLACK, color, true); time += kHalfStrideTime; + new WalkingFade(time, kLedStart - 1, kStride, 160, BLACK, color, true); time += kHalfStrideTime; + time += 3 * kHalfStrideTime; // should create three complete pixels + new WalkingFade(time, kLedStart, kStride, 160, color, BLACK, true); time += kHalfStrideTime; + new WalkingFade(time, kLedStart - 1, kStride, 160, color, BLACK, true); time += kHalfStrideTime; + time += kDotSpaceTime; + break; + } + case '/': // fall-through + case ' ': time += kSpaceTime; break; + } + } + finaliser_.time_ = time + kLedStart * kHalfStrideTime + 2000; + Schedule(&finaliser_); + } + +private: + ProgramWatchdog finaliser_; +}; + void init_board() { @@ -440,7 +523,8 @@ init_board(); g_watchdog = &g_watchdog_impl; - MultiDropBucketFillProgram multi_drop; + //MultiDropBucketFillProgram multi_drop; + MorseGoogleProgram morse; supervisor.ScheduleProgram();