RGB LEDS of the neopixels

Dependencies:   C12832_lcd PixelArray WS2812 mbed

Fork of WS2812_Example by Brian Daniels

Revision:
3:d429d33844c9
Parent:
2:cb82a3dc4031
Child:
4:7a998a6934f1
--- a/main.cpp	Thu Feb 12 21:55:24 2015 +0000
+++ b/main.cpp	Wed Apr 15 17:58:55 2015 +0000
@@ -2,15 +2,14 @@
 #include "WS2812.h"
 #include "PixelArray.h"
 
-#define WS2812_BUF 150
-#define NUM_COLORS 6
-#define NUM_LEDS_PER_COLOR 10
-
+#define WS2812_BUF 3
+#define NUM_COLORS 9
+#define NUM_LEDS_PER_COLOR 3
 PixelArray px(WS2812_BUF);
 
 // See the program page for information on the timing numbers
 // The given numbers are for the K64F
-WS2812 ws(D9, WS2812_BUF, 0, 5, 5, 0);
+WS2812 ws(p9, WS2812_BUF, 5, 10, 10, 15);
 
 int main()
 {
@@ -18,8 +17,10 @@
     ws.useII(WS2812::PER_PIXEL); // use per-pixel intensity scaling
     
     // set up the colours we want to draw with
-    int colorbuf[NUM_COLORS] = {0x2f0000,0x2f2f00,0x002f00,0x002f2f,0x00002f,0x2f002f};
-
+    int colorbuf[NUM_COLORS] = {0x000000};//,0x00f0ff,0x00ff00,0x00ffff,0xffffff,0x00ff00,0x00ffff,0x0000ff,0xff00ff};
+    
+   
+        
     // for each of the colours (j) write out 10 of them
     // the pixels are written at the colour*10, plus the colour position
     // all modulus 60 so it wraps around
@@ -31,17 +32,45 @@
     // compute and write the II value for each pixel
     for (int j=0; j<WS2812_BUF; j++) {
         // px.SetI(pixel position, II value)
-        px.SetI(j%WS2812_BUF, 0xf+(0xf*(j%NUM_LEDS_PER_COLOR)));
+        //px.SetI(j%WS2812_BUF, 0xff+(0xf*(j%NUM_LEDS_PER_COLOR)));     //full brightness
+        px.SetI(j%WS2812_BUF, 0xf+(0xf*(j%NUM_LEDS_PER_COLOR)));        //Dim lighting
     }
 
 
     // Now the buffer is written, rotate it
     // by writing it out with an increasing offset
-    while (1) {
+     while (1) {
+        if(colorbuf[0]>=0xfffffe)
+            {
+            colorbuf[0]=0x000000;    
+            } 
+            
+        if(colorbuf[0]<=0x0000ff)
+            {
+            colorbuf[0]=colorbuf[0]+0x00000f;
+            //colorbuf[0] = 0x000000;    
+            }
+        else if(colorbuf[0]<=0x00ffff)
+            {
+            colorbuf[0]=colorbuf[0]+0x000f00;  
+            }
+        else if(colorbuf[0]<=0xfffffe)
+            {
+            colorbuf[0]=colorbuf[0]+0x0f0000;    
+            } 
+        
+        
+               
+
+        for (int i = 0; i < WS2812_BUF; i++) {
+            px.Set(i, colorbuf[(i / NUM_LEDS_PER_COLOR) % NUM_COLORS]);
+            px.SetI(i%WS2812_BUF, 0xf+(0xf*(i%NUM_LEDS_PER_COLOR)));        //Dim lighting
+        }
         for (int z=WS2812_BUF; z >= 0 ; z--) {
             ws.write_offsets(px.getBuf(),z,z,z);
-            wait(0.075);
+            //wait(0.5);
+    
+            }
+        wait(0.1);
         }
-    }
-
 }