Light Show library for organic, calm, light display.

Dependencies:   BLE_API mbed nRF51822

Fork of mbed_blinky by Mbed

Files at this revision

API Documentation at this revision

Comitter:
nargetdev
Date:
Sun Oct 11 03:12:07 2015 +0000
Parent:
9:1bd0f7a2ee71
Child:
11:2d3cc5459d5b
Child:
12:5d4e1c27a666
Commit message:
Fade out smooth -- KG

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Oct 11 01:15:52 2015 +0000
+++ b/main.cpp	Sun Oct 11 03:12:07 2015 +0000
@@ -1,5 +1,7 @@
 #include "mbed.h"
  
+ 
+#define HYSTERESIS_QUANTITY  1.57079632679
 #define calibrationTime 10
 unsigned long seed = 47;
 
@@ -59,27 +61,48 @@
 void show(){
   float in, rout, bout, gout;
   bool tit = true;
+
+  unsigned int rgb = 0x0;
     pc.printf("showing...\n");
     
     float hysteresis = 0;
 
-  for (in = -1.571; motion && in < 6.283; in = in + 0.00628)
+  for (in = -1.571; in < hysteresis || (rgb ^ 0x7); in = in + 0.00628)
   {
     unsigned int i = motion;
     if (motion){
-        hysteresis = in + 6.283;
+        hysteresis = in + HYSTERESIS_QUANTITY;
         pc.printf("\n-----\nextra_hysteresis\n-----\n");
     }
     tit = !tit;
-    rout = sin(in) + 1.0;
-    bout = sin(in + 1.3*(in+1.571) ) + 1.0;
-    gout = sin(in + 4.2*(in+1.571) ) + 1.0;
+    if (!(rgb & 0x1))
+        rout = sin(in) + 1.0;
+    else
+        rout = 0.0f;
+    if (!(rgb & 0x2))
+        bout = sin(in + 1.3*(in+1.571) ) + 1.0;
+    else
+        bout = 0.0f;
+    if (!(rgb & 0x4))
+        gout = sin(in + 4.2*(in+1.571) ) + 1.0;
+    else
+        gout = 0.0f;
+        
     if (tit)
         pc.printf("%f\t%f\t%f\n",rout,bout,gout);
 
-        red.write(rout/2.0);
-        green.write(gout/2.0);
-        blue.write(bout/2.0);
+    red.write(rout/2.0);
+    green.write(gout/2.0);
+    blue.write(bout/2.0);
+    
+    if (in > hysteresis){
+        if (rout < 0.01)
+            rgb |= 0x1;
+        if (gout < 0.01)
+            rgb |= 0x2;
+        if (bout < 0.01)
+            rgb |= 0x4;
+    }
     wait(.005);
   }
 }