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:
- 1:1a0d5a780e57
- Parent:
- 0:109a7a5e3e6e
- Child:
- 2:590e99f4a313
diff -r 109a7a5e3e6e -r 1a0d5a780e57 main.cpp
--- a/main.cpp Sat Sep 21 13:07:11 2013 +0000
+++ b/main.cpp Sat Sep 21 15:21:53 2013 +0000
@@ -10,6 +10,8 @@
DigitalOut latch(p16);
DigitalOut strobe(p17);
+#define LENGTH 160
+
uint8_t strip[160];
#define BLACK 0x80
@@ -105,6 +107,43 @@
bool fast_;
};
+class WalkingFadeInOut : public Schedulable {
+public:
+ WalkingFadeInOut(int start_time, int led, int stride, uint8_t a, uint8_t b, bool fast)
+ : led_(led - stride), stride_(stride), a_(a), b_(b), fast_(fast), step_(true) {
+ time_ = start_time;
+ Schedule(this);
+ }
+
+ virtual void Run() {
+ if (step_) {
+ step_ = false;
+ if (led_ >= 0) strip[led_] = a_;
+ led_ += stride_;
+ led_ %= LENGTH;
+ } else {
+ step_ = true;
+ }
+ strip[led_] = getcolor(a_, b_);
+ if (fast_) {
+ strip[led_] |= 0x40;
+ time_ += 128;
+ } else {
+ time_ += 256;
+ }
+ strip_changed = true;
+ swap(a_,b_);
+ Schedule(this);
+ }
+
+private:
+ int led_, stride_;
+ uint8_t a_,b_;
+ bool fast_, step_;
+
+};
+
+
int main() {
Ticker t;
pc.baud(115200);
@@ -118,13 +157,18 @@
myled = 1;
memset(strip, 0x80, sizeof(strip));
write_strip(strip, sizeof(strip));
- t.attach(&tick_cb, 1.0/400);
+ t.attach(&tick_cb, 1.0/1000);
memset(strip, 0x0, sizeof(strip));
- new RepeatedFadeInOut(0, 0, BLACK, RED, false);
+ /*new RepeatedFadeInOut(0, 0, BLACK, RED, false);
new RepeatedFadeInOut(171, 1, BLACK, RED, false);
new RepeatedFadeInOut(341, 2, BLACK, RED, false);
+*/
+ int stride = 7;
+ for (int i = 0; i < stride; i++) {
+ new WalkingFadeInOut((256 * i / stride), i, stride, BLACK, GREEN, true);
+ }
while(1) {
while (task_list.empty() || global_tick < task_list.top()->time_) {
@@ -143,7 +187,7 @@
strip[2] = BLUE;
strip[3] = getcolor(BLACK, RED);
- write_strip(strip, sizeof(strip));
+ (strip, sizeof(strip));
myled = 1;
int count = 0;
