tweaked library for debug but have to commit to publish...

Dependents:   ChrisRGB-Ring

Fork of WS2812 by Chris Styles

Revision:
4:b230e85fc5e7
Parent:
3:d56ffdf7beeb
Child:
5:a07522fe36d4
--- a/WS2812.cpp	Mon Aug 04 16:22:40 2014 +0000
+++ b/WS2812.cpp	Wed Aug 06 08:34:32 2014 +0000
@@ -10,17 +10,17 @@
 }
 
 
-
 WS2812::~WS2812()
 {
 
 }
 
-void WS2812::write(int buff[])
+
+void WS2812::write(int buf[])
 {
     // for each of the data points in the buffer
     for (int i = 0; i < __size ; i++) {
-        __write(buff[i]);
+        __write(buf[i]);
     }
 }
 
@@ -58,6 +58,8 @@
     // Inout format : IIRRGGBB
     unsigned char agrb[4] = {0x0, 0x0, 0x0, 0x0};
 
+    unsigned char sf; // scaling factor for  II
+
     // extract colour fields from incoming
     // 0 = blue, 1 = red, 2 = green, 3 = brightness
     agrb[0] = color & 0x000000FF;
@@ -65,19 +67,22 @@
     agrb[2] = (color & 0x0000FF00) >> 8;
     agrb[3] = (color & 0xFF000000) >> 24;
 
-    // apply intensity
-    // 1 use global, 2=per pixel
+    // set and intensity scaling factor (global, per pixel, none)
     if (__use_II == 1) {
-        for (int clr = 2; clr >= 0; clr--) {
-            agrb[clr] = ((agrb[clr] * __II) >> 8);
-        }
+        sf = __II;
     } else if (__use_II == 2) {
-        for (int clr = 2; clr >= 0; clr--) {
-            agrb[clr] = ((agrb[clr] * agrb[3]) >> 8);
-        }
+        sf = agrb[3];
+    } else {
+        sf = 0xFF;
     }
 
+    // Apply the scaling factor to each othe colour components
+    for (int clr = 2; clr >= 0; clr--) {
+        agrb[clr] = ((agrb[clr] * sf) >> 8);
+    }
 
+    // For each colour component G,R,B
+    // shift out the data 7..0, writing a SPI frame per bit
     // green=2,red=1,blue=0,
     for (int clr = 2; clr >= 0; clr--) {
         for (int bit = 7 ; bit >= 0 ; bit--) {