A library for SPI control of adafruit's neopixel ring and addressable LEDs.

Dependencies:   PixelArray

Dependents:   TI_NEOPIXEL_SPI_SAMPLE

Revision:
2:0148ac5c90fa
Parent:
0:c28aa7d4f97e
Child:
3:f0859c280204
Child:
5:69bb2a2fa11f
--- a/TI_NEOPIXEL_SPI.cpp	Wed Jul 10 16:37:51 2019 +0000
+++ b/TI_NEOPIXEL_SPI.cpp	Sun Jul 28 00:13:03 2019 +0000
@@ -20,47 +20,59 @@
     _ledStrip.update(colors, count);
 }
 
-void TI_NEOPIXEL_SPI::switchLightOn(int count)
+void TI_NEOPIXEL_SPI::switchLightOn(int count,  int startCount, int endCount, rgbColor rgbColor)
 {
     neopixel::Pixel colors[count];
 
     for (int i = 0; i < count; i++)
     {
-        colors[i].red = 50;
-        colors[i].green = 10;
-        colors[i].blue = 170;
+        if (startCount <= i && i < endCount) {
+            colors[i].red = rgbColor.red;
+            colors[i].green = rgbColor.green;
+            colors[i].blue = rgbColor.blue;
+        } else {
+            colors[i].red = 0;
+            colors[i].green = 0;
+            colors[i].blue = 0;
+        }
     }
 
     _ledStrip.update(colors, count);
 }
 
-void TI_NEOPIXEL_SPI::changeColor(int count, rgbColor rgbColor)
+void TI_NEOPIXEL_SPI::changeColor(int count, int startCount, int endCount, rgbColor rgbColor)
 {
     neopixel::Pixel colors[count];
 
     for (int i = 0; i < count; i++)
     {
-        colors[i].red = rgbColor.red;
-        colors[i].green = rgbColor.green;
-        colors[i].blue = rgbColor.blue;
+        if (startCount <= i && i < endCount) {
+            colors[i].red = rgbColor.red;
+            colors[i].green = rgbColor.green;
+            colors[i].blue = rgbColor.blue;
+        } else {
+            colors[i].red = 0;
+            colors[i].green = 0;
+            colors[i].blue = 0;
+        }
     }
 
     _ledStrip.update(colors, count);
 }
 
-void TI_NEOPIXEL_SPI::changePointColor(int count, rgbColor topColor, rgbColor bottomColor)
+void TI_NEOPIXEL_SPI::changePointColor(int count, int topIndex, int endIndex, rgbColor topColor, rgbColor bottomColor)
 {
     neopixel::Pixel colors[count];
 
     for (int i = 0; i < count; i++)
     {
-        if (i == 0)
+        if (i == topIndex)
         {
             colors[i].red = topColor.red;
             colors[i].green = topColor.green;
             colors[i].blue = topColor.blue;
         }
-        else if (i == count / 2)
+        else if (i == endIndex)
         {
             colors[i].red = bottomColor.red;
             colors[i].green = bottomColor.green;
@@ -77,7 +89,7 @@
     _ledStrip.update(colors, count);
 }
 
-void TI_NEOPIXEL_SPI::circle(int count, rgbColor rgbColor)
+void TI_NEOPIXEL_SPI::circle(int count, int startCount, int endCount, rgbColor rgbColor)
 {
     for (int j = 0; j < count; j++)
     {
@@ -85,11 +97,17 @@
 
         for (int i = 0; i < count; i++)
         {
-            if (j >= i)
+            if (i <= j)
             {
-                colors[i].red = rgbColor.red;
-                colors[i].green = rgbColor.green;
-                colors[i].blue = rgbColor.blue;
+                if (startCount <= i && i < endCount) {
+                    colors[i].red = rgbColor.red;
+                    colors[i].green = rgbColor.green;
+                    colors[i].blue = rgbColor.blue;
+                } else {
+                    colors[i].red = 0;
+                    colors[i].green = 0;
+                    colors[i].blue = 0;
+                }
             }
             else
             {
@@ -100,7 +118,10 @@
         }
 
         _ledStrip.update(colors, count);
-        wait(0.07);
+
+        if (startCount <= j && j < endCount) {
+            wait(0.07);
+        }
     }
 }
 
@@ -133,6 +154,40 @@
     }
 }
 
+void TI_NEOPIXEL_SPI::chaseRainbow(int count)
+{
+    for (int j = 0; j < count; j++)
+    {
+        neopixel::Pixel colors[count];
+
+        for (int i = 0; i < count; i++)
+        {
+            if (i <= j)
+            {
+                uint8_t phase = 256 / count * i;
+                rgbColor rgbColor = convertHsvToRgb(phase / 256.0, 1.0, 1.0);
+                colors[i].red = rgbColor.red;
+                colors[i].green = rgbColor.green;
+                colors[i].blue = rgbColor.blue;
+
+                // LEDを節約
+                colors[i-4].red = 0;
+                colors[i-4].green = 0;
+                colors[i-4].blue = 0;
+            }
+            else
+            {
+                colors[i].red = 0;
+                colors[i].green = 0;
+                colors[i].blue = 0;
+            }
+        }
+
+        _ledStrip.update(colors, count);
+        wait(0.06);
+    }
+}
+
 void TI_NEOPIXEL_SPI::circleRainbow(int count)
 {
     for (int j = 0; j < count; j++)