A simple example to drive an APA-102 LED strip.

Dependencies:   mbed APA102b Ping SLCD

Files at this revision

API Documentation at this revision

Comitter:
rosienej
Date:
Mon Apr 06 13:57:50 2015 +0000
Parent:
1:2d02f55d47c5
Child:
3:2788a714b18e
Commit message:
Demo of a different LED display geometery

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Mar 14 20:45:48 2015 +0000
+++ b/main.cpp	Mon Apr 06 13:57:50 2015 +0000
@@ -71,6 +71,50 @@
     unsigned int Pixel;
     unsigned int Pixels[N];
     
+    float hue,sat,ints;
+    
+    const int NumberOfRays = 19;
+    
+    
+    float RayHues[19] =   // hues are 0 to 360, http://en.wikipedia.org/wiki/HSL_and_HSV
+    {0.0,19.0,38.0,57.0,76.0,95.0,114.0,
+    133.0,152.0,171.0,190.0,209.0,228.0,
+    247.0,266.0,285.0,304.0,323.0,342.0};
+    
+    float RaySats[19] =   // hues are 0 to 360, http://en.wikipedia.org/wiki/HSL_and_HSV
+    {0.8,0.8,0.8,0.8,0.8,0.8,0.8,
+     0.8,0.8,0.8,0.8,0.8,0.8,0.8,
+     0.8,0.8,0.8,0.8,0.8};
+    
+     float RayInts[19] =   // hues are 0 to 360, http://en.wikipedia.org/wiki/HSL_and_HSV
+    {0.8,0.8,0.8,0.8,0.8,0.8,0.8,
+     0.8,0.8,0.8,0.8,0.8,0.8,0.8,
+     0.8,0.8,0.8,0.8,0.8};
+    
+    int RayLengths[19] = {3, 4, 5, 4, 2, 5, 4, 2,   4,5,3,4,3,2,2,3,2,4,5};
+    
+    int Rays[19][5] = {
+        {1 ,20,39, 0, 0},  //3 
+        {2 ,21,40,53, 0},  //4
+        {3 ,22,41,54,64},  //5
+        {4 ,23,42,55, 0},  //4
+        {5 ,24, 0, 0, 0},  //2
+        {6 ,25,43,56,65},  //5
+        {7 ,26,44,57, 0},  //4
+        {8 ,27, 0, 0, 0},  //2
+        {9 ,28,45,58, 0},  //4
+        {10,29,46,59,66},  //5
+        {11,30,47, 0, 0},  //3
+        {12,31,48,60, 0},  //4
+        {13,32,49, 0, 0},  //3
+        {14,33, 0, 0, 0},  //2
+        {15,34, 0, 0, 0},  //2
+        {16,35,50, 0, 0},  //3
+        {17,36, 0, 0, 0},  //2
+        {18,37,51,61,0},   //4
+        {19,38,52,62,63}}; //5
+        
+    
     int colors=0x000000;
     LEDs.SetBuffer(Pixels,1,N, N,0, false,false); 
     
@@ -80,18 +124,25 @@
         range = ping.Read_cm();
         
         
-        for(int i=0;i<N;i++)
+        for(int i=0;i<NumberOfRays;i++)
         {   
-            hsi2rgb(1.0*(i+colors), 0.8, 0.8,rgb);
-            r = rgb[0];
-            g = rgb[1];
-            b = rgb[2];
-            
-            Pixel=LEDs.IRGB(7,r,g,b);
-            Pixels[i]=Pixel;
-           
+          for(int j=0;j<RayLengths[i];j++)
+          {
+            for(int k=0;k<j;k++)
+            {
+                hue  = RayHues[i];
+                sat  = RaySats[i];
+                ints = RayInts[i];
+                hsi2rgb(hue, sat, ints,rgb);
+                r = rgb[0];
+                g = rgb[1];
+                b = rgb[2];
+                
+                Pixel=LEDs.IRGB(7,r,g,b);
+                Pixels[Rays[i][k]-1]=Pixel;  // arrays in C++ start at zero.  Need to subtract 1.
+            }
             } 
-        
+         }
         LEDs.Repaint();
         colors+=range/10;
     }