David Rhodes / LPC1114_Neopixel

Dependencies:   mbed

Fork of LEDTape_WS2812 by Suga koubou

Files at this revision

API Documentation at this revision

Comitter:
rhodes42
Date:
Tue Apr 08 20:56:03 2014 +0000
Parent:
2:61abc599f31f
Commit message:
added scalebrightness and changed main demo

Changed in this revision

LEDStripFunctions.cpp Show annotated file Show diff for this revision Revisions of this file
LEDStripFunctions.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 61abc599f31f -r 743570d993aa LEDStripFunctions.cpp
--- a/LEDStripFunctions.cpp	Mon Mar 24 10:00:54 2014 +0000
+++ b/LEDStripFunctions.cpp	Tue Apr 08 20:56:03 2014 +0000
@@ -51,4 +51,27 @@
     {
         if ((i >= start) && ((i - start) % mod == 0)) buffer[i] = color;   
     }   
+}
+
+
+void scaleBrightness(uint32_t *buffer, int divider, int n)
+{
+    int i, r, g, b;
+    for (i = 0; i < n; i++)
+    {
+        r = (buffer[i] >> 16) & 0xff;
+        g = (buffer[i] >> 8 ) & 0xff;
+        b = (buffer[i]      ) & 0xff;
+        r /= divider;
+        g /= divider;
+        b /= divider;
+        buffer[i] = (r << 16) | (g << 8) | (b);
+    } 
+}
+
+void setPixelRGB(int pixel, int r, int g, int b)
+{
+       
+    int pix = (r << 16) | (g << 8) | (b);
+    tapeSet(pixel, pix);
 }
\ No newline at end of file
diff -r 61abc599f31f -r 743570d993aa LEDStripFunctions.h
--- a/LEDStripFunctions.h	Mon Mar 24 10:00:54 2014 +0000
+++ b/LEDStripFunctions.h	Tue Apr 08 20:56:03 2014 +0000
@@ -6,3 +6,5 @@
 void shiftAllFwd(uint32_t *buffer, int n);
 void shiftAllRev(uint32_t *buffer, int n);
 void setEveryMod(uint32_t * buffer, uint32_t color, int mod, int start, int n);
+void scaleBrightness(uint32_t *buffer, int divider, int n);
+void setPixelRGB(int pixel, int r, int g, int b);
\ No newline at end of file
diff -r 61abc599f31f -r 743570d993aa main.cpp
--- a/main.cpp	Mon Mar 24 10:00:54 2014 +0000
+++ b/main.cpp	Tue Apr 08 20:56:03 2014 +0000
@@ -34,10 +34,13 @@
         colors[k] = (k*260000);
     }*/
     
-    setEveryMod(colors, 0xff, 3, 0, numLEDs);
-    setEveryMod(colors, (0xff<<8), 3, 1, numLEDs);
-    setEveryMod(colors, (0xff<<16), 3, 2, numLEDs);
-    
+    setEveryMod(colors, 0xff, 6, 0, numLEDs);
+    setEveryMod(colors, (0xff<<8), 6, 1, numLEDs);
+    setEveryMod(colors, (0xff<<16), 6, 2, numLEDs);
+    setEveryMod(colors, (0xff<<16)|(0xff<<8), 6, 3, numLEDs);
+    setEveryMod(colors, (0xff<<8)|(0xff), 6, 4, numLEDs);
+    setEveryMod(colors, (0xff<<16)|(0xff), 6, 5, numLEDs);
+    scaleBrightness(colors, 8, numLEDs);
 
     for (;;) {
             led1 = 1;           
@@ -51,13 +54,13 @@
                 setAll(colors, numLEDs);
                 led1 = 0;
                 tapeSend();
-                wait_ms(100);
+                wait_ms(500);
                 
                 shiftAllFwd(colors, numLEDs);                
                 setAll(colors, numLEDs);
                 led1 = 1;
                 tapeSend();
-                wait_ms(100);
+                wait_ms(500);
             }
     }
 }