Julio G / Mbed 2 deprecated LedStrip

Dependencies:   mbed

Fork of LedStrip_test by Balazs Racz

Files at this revision

API Documentation at this revision

Comitter:
juliogerchman
Date:
Sat Sep 21 22:14:57 2013 +0000
Parent:
8:77fd54b4864c
Commit message:
cyclecolors not working yet

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Sep 21 20:49:33 2013 +0000
+++ b/main.cpp	Sat Sep 21 22:14:57 2013 +0000
@@ -353,6 +353,52 @@
 } g_watchdog_impl;
 
 
+
+const int CycleColorsRegions[][2] = {
+    {5, 10},
+    {15, 10},
+    {35, 5},
+    {40, 50}
+};
+
+class CycleColors : public Schedulable
+{
+public:
+    CycleColors(bool fast, int cycle_count) : fast_(fast), cycle_count_(cycle_count), current_cycle_(0) {
+        fade_out_time_ = fast_ ? 256 : 512;
+        supervisor.RegisterProgram(this);
+    }
+    
+    virtual void Run() {
+        strip[100] = RED;
+        strip_changed = true;
+        
+        int next_cycle_start_time = global_tick;
+        for (int region = 0; region < sizeof(CycleColorsRegions) / sizeof(CycleColorsRegions[0]); ++region) {
+            int region_start_led = CycleColorsRegions[region][0];
+            int region_length = CycleColorsRegions[region][1];
+            int region_from_color = google_colors[(current_cycle_ + region) % sizeof(google_colors)];
+            int region_to_color = google_colors[(region_from_color + 1) % sizeof(google_colors)];
+            new FadeFillRegion(next_cycle_start_time, region_start_led, region_length, region_from_color, region_to_color, fast_, NULL);
+        }
+
+        ++current_cycle_;
+        if (current_cycle_ < cycle_count_) {
+            time_ += fade_out_time_;
+            Schedule(this);
+        } else {
+            supervisor.CurrentProgramDone();
+        }
+    }
+
+private:
+    bool fast_;
+    int fade_out_time_;
+    int cycle_count_;
+    int current_cycle_;
+};
+
+
 class MultiDropBucketFillProgram : public Schedulable
 {
 public:
@@ -440,7 +486,8 @@
     init_board();
     g_watchdog = &g_watchdog_impl;
     
-    MultiDropBucketFillProgram multi_drop;
+    // MultiDropBucketFillProgram multi_drop;
+    CycleColors cycle_colors(false, 5);
     
     supervisor.ScheduleProgram();