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.
Fork of LedStrip_test by
Diff: main.cpp
- Revision:
- 4:e3b6f5741d9d
- Parent:
- 3:42efa00ffef4
- Child:
- 8:77fd54b4864c
--- a/main.cpp Sat Sep 21 19:39:02 2013 +0000 +++ b/main.cpp Sat Sep 21 20:28:03 2013 +0000 @@ -206,11 +206,33 @@ Schedulable* next_; }; +class FadeFillRegion : public Schedulable { +public: + FadeFillRegion(int start_time, int start_led, int length, uint8_t from_color, uint8_t to_color, bool fast) + : start_led_(start_led), length_(length), from_color_(from_color), to_color_(to_color), fast_(fast) { + time_ = start_time; + Schedule(this); + } + + virtual void Run() { + for (int i = start_led_; i < start_led_ + length_; ++i) { + strip[i] = getcolor(from_color_, to_color_) | (fast_ ? FAST : 0); + } + strip_changed = true; + delete this; + } + +private: + int start_led_, length_; + uint8_t from_color_, to_color_; + bool fast_; +}; + /* Keep dropping water drops in a bucket, until it fills up. */ class DropBucketFill : public Schedulable { public: - DropBucketFill(int start_time, int start_led, int length, int drop_size, uint8_t from_color, uint8_t to_color) - : start_led_(start_led), length_(length), drop_size_(drop_size), from_color_(from_color), to_color_(to_color) { + DropBucketFill(int start_time, int start_led, int length, int drop_size, uint8_t from_color, uint8_t to_color, int fade_out_pause, uint8_t fade_out_color) + : start_led_(start_led), length_(length), original_length_(length), drop_size_(drop_size), from_color_(from_color), to_color_(to_color), fade_out_pause_(fade_out_pause), fade_out_color_(fade_out_color) { time_ = start_time; Schedule(this); } @@ -222,22 +244,24 @@ if (length_ > 0) { // There's still space in the bucket. Drop a new drop. for (int i = 0; i < min(drop_size_, length_); ++i) { - Schedulable* next_drop = NULL; - next_drop = this; + Schedulable* next_drop = this; new RegionWalkingFadeInOut(time_ + (256 * i / drop_size_), i, drop_size_, start_led_, length_, from_color_, to_color_, true, false, true, next_drop); } length_--; } else { // There's no more space in the bucket. Bail out. + new FadeFillRegion(global_tick + fade_out_pause_, start_led_, original_length_, to_color_, fade_out_color_, false); delete this; return; } } private: - int start_led_, length_; + int start_led_, length_, original_length_; int drop_size_; uint8_t from_color_, to_color_; + int fade_out_pause_; + uint8_t fade_out_color_; }; void init_board() { @@ -282,9 +306,8 @@ //new RegionWalkingFadeInOut((256 * i / stride), i, stride, 5, 30, BLACK, BLUE, true, false); } - new DropBucketFill(0, 10, 20, 3, BLACK, BLUE); - - new DropBucketFill(0, 30, 20, 11, BLACK, GREEN); + new DropBucketFill(0, 10, 20, 3, BLACK, BLUE, 2560, BLACK); + new DropBucketFill(0, 30, 20, 11, BLACK, GREEN, 2560, BLACK); run_loop(); } \ No newline at end of file