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:
Tue Apr 14 00:15:32 2015 +0000
Parent:
5:0b6842abebac
Commit message:
added a few more modes;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 0b6842abebac -r 27f43abd16e2 main.cpp
--- a/main.cpp	Tue Apr 07 14:31:11 2015 +0000
+++ b/main.cpp	Tue Apr 14 00:15:32 2015 +0000
@@ -53,7 +53,14 @@
   rgb[1]=g;
   rgb[2]=b;
 }
+/// pseudo random number
+unsigned int m_z=12434,m_w=33254;
 
+unsigned int rnd() {
+    m_z = 36969 * (m_z & 65535) + (m_z >>16);
+    m_w = 18000 * (m_w & 65535) + (m_w >>16);
+    return ((m_z <<16) + m_w);
+}
 
 int main()
 {
@@ -70,7 +77,7 @@
     int rgb[3]; 
     unsigned char r,g,b;
     const int N=66;  // Number of APA-102 Elements 
-    //const int N=144;
+   // const int N=144;
     int range;
     unsigned int Pixel;
     unsigned int Pixels[N];
@@ -123,11 +130,13 @@
     int colors=0x000000;
     
     int Mode=0;
-    const int NModes = 4;
+    const int NModes = 8;
     
     LEDs.SetBuffer(Pixels,1,N, N,0, false,false); 
         slcd.Home();                                   
         slcd.printf("%d",Mode);   
+    
+    
        
     while (true) {
         ping.Send();    
@@ -143,6 +152,10 @@
             
             }
         
+        for(int i = 0;i<19;i++) RaySats[i] = 0.8;
+        for(int i = 0;i<19;i++) RayInts[i] = 0.8;
+        
+        
         switch(Mode){
             case 0: hue_adjust =0;
                     break; // just display the last "static" image
@@ -152,6 +165,15 @@
                     break;
             case 3: hue_adjust++; // spin at a fixed rate
                     break;
+            case 4: for(int i = 0;i<19;i++) RaySats[i] = 1.0/(1.0*(rnd()%16+1));
+                    break;
+            case 5: for(int i = 0;i<19;i++) RayInts[i] = 1.0/(1.0*(rnd()%16+1));
+                    break;
+            case 6: for(int i = 0;i<19;i++) RayInts[i] = 1.0/(1.0*(rnd()%16+1));
+                    for(int i = 0;i<19;i++) RaySats[i] = 1.0/(1.0*(rnd()%16+1));
+                    break;
+            case 7: hue_adjust = rnd()%16;
+                    break;
                     
             }
         
@@ -160,8 +182,7 @@
         {   
           for(int j=0;j<RayLengths[i];j++)
           {
-            for(int k=0;k<j;k++)
-            {
+        
                 hue  = RayHues[i]+ hue_adjust;
                 sat  = RaySats[i];
                 ints = RayInts[i];
@@ -171,8 +192,8 @@
                 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.
-            }
+                Pixels[Rays[i][j]-1]=Pixel;  // arrays in C++ start at zero.  Need to subtract 1.
+            
             } 
          }
    /*