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

Dependencies:   PixelArray

Dependents:   TI_NEOPIXEL_SPI_SAMPLE

Revision:
4:70bc3528e07e
Parent:
3:f0859c280204
--- a/TI_NEOPIXEL_SPI.cpp	Thu Jan 02 08:14:13 2020 +0000
+++ b/TI_NEOPIXEL_SPI.cpp	Thu Jan 02 14:22:55 2020 +0000
@@ -130,7 +130,14 @@
 
         if (startCount <= j && j < endCount)
         {
-            wait(0.07);
+            if (count == 16)
+            {
+                wait(0.05);
+            }
+            else
+            {
+                wait(0.015);
+            }
         }
     }
 }
@@ -147,9 +154,7 @@
         pixels[j].b = c2.blue;
     }
 
-    _neoPixel.send(pixels, virtualCount);
-
-    for (int j = 0; j < virtualCount + bufferCount; j++)
+    for (int j = 0; j < count; j++)
     {
         pixels[j].r = c1.red;
         pixels[j].g = c1.green;
@@ -160,11 +165,103 @@
         pixels[j - bufferCount].b = c2.blue;
 
         _neoPixel.send(pixels, virtualCount);
-        wait(0.05);
+
+        if (count == 16)
+        {
+            wait(0.05);
+        }
+        else
+        {
+            wait(0.015);
+        }
     }
 }
 
-void TI_NEOPIXEL_SPI::chaseRainbow(int count)
+void TI_NEOPIXEL_SPI::chase2(int count, int bufferCount, rgbColor c1, rgbColor c2)
+{
+    for (int j = 0; j < count; j++)
+    {
+        Pixel pixels[count];
+
+        for (int i = 0; i < count; i++)
+        {
+            if (i <= j)
+            {
+                pixels[i].r = c1.red;
+                pixels[i].g = c1.green;
+                pixels[i].b = c1.blue;
+
+                // LEDを節約
+                pixels[i - bufferCount].r = c2.red;
+                pixels[i - bufferCount].g = c2.green;
+                pixels[i - bufferCount].b = c2.blue;
+            }
+            else
+            {
+                pixels[i].r = c2.red;
+                pixels[i].g = c2.green;
+                pixels[i].b = c2.blue;
+            }
+        }
+
+        _neoPixel.send(pixels, count);
+
+        if (count == 16)
+        {
+            wait(0.05);
+        }
+        else
+        {
+            wait(0.015);
+        }
+    }
+}
+
+void TI_NEOPIXEL_SPI::chaseReverse(int count, int bufferCount, rgbColor c1, rgbColor c2)
+{
+    printf("chaseReverse \n");
+
+    Pixel pixels[count];
+
+    for (int j = 0; j <= count; j++)
+    {
+        pixels[j].r = c2.red;
+        pixels[j].g = c2.green;
+        pixels[j].b = c2.blue;
+    }
+
+    _neoPixel.send(pixels, count);
+
+    for (int j = 0; j <= count; j++)
+    {
+        if (0 <= (count - j))
+        {
+            pixels[count - j].r = c1.red;
+            pixels[count - j].g = c1.green;
+            pixels[count - j].b = c1.blue;
+        }
+
+        if (bufferCount <= j)
+        {
+            pixels[count + bufferCount - j].r = c2.red;
+            pixels[count + bufferCount - j].g = c2.green;
+            pixels[count + bufferCount - j].b = c2.blue;
+        }
+
+        _neoPixel.send(pixels, count);
+
+        if (count == 16)
+        {
+            wait(0.05);
+        }
+        else
+        {
+            wait(0.015);
+        }
+    }
+}
+
+void TI_NEOPIXEL_SPI::chaseRainbow(int count, int bufferCount)
 {
     for (int j = 0; j < count; j++)
     {
@@ -181,9 +278,9 @@
                 pixels[i].b = rgbColor.blue;
 
                 // LEDを節約
-                pixels[i - 4].r = 0;
-                pixels[i - 4].g = 0;
-                pixels[i - 4].b = 0;
+                pixels[i - bufferCount].r = 0;
+                pixels[i - bufferCount].g = 0;
+                pixels[i - bufferCount].b = 0;
             }
             else
             {
@@ -194,7 +291,15 @@
         }
 
         _neoPixel.send(pixels, count);
-        wait(0.06);
+
+        if (count == 16)
+        {
+            wait(0.05);
+        }
+        else
+        {
+            wait(0.015);
+        }
     }
 }
 
@@ -223,7 +328,78 @@
         }
 
         _neoPixel.send(pixels, count);
-        wait(0.06);
+
+        if (count == 16)
+        {
+            wait(0.05);
+        }
+        else
+        {
+            wait(0.015);
+        }
+    }
+}
+
+void TI_NEOPIXEL_SPI::moon(int count, int startIndex, int stopIndex, rgbColor c1, rgbColor c2)
+{
+
+    Pixel pixels[count];
+
+    for (int j = 0; j < count; j++)
+    {
+        if (0 <= j && j <= count)
+        {
+            pixels[j].r = c2.red;
+            pixels[j].g = c2.green;
+            pixels[j].b = c2.blue;
+        }
+    }
+
+    int loopCount = (stopIndex - startIndex) / 2;
+    int middlePoint = startIndex + loopCount;
+
+    for (int i = 0; i <= loopCount - 1; i++)
+    {
+        pixels[middlePoint + i].r = c1.red;
+        pixels[middlePoint + i].g = c1.green;
+        pixels[middlePoint + i].b = c1.blue;
+
+        pixels[middlePoint - i].r = c1.red;
+        pixels[middlePoint - i].g = c1.green;
+        pixels[middlePoint - i].b = c1.blue;
+
+        _neoPixel.send(pixels, count);
+
+        if (count == 16)
+        {
+            wait(0.05);
+        }
+        else
+        {
+            wait(0.04);
+        }
+    }
+
+    for (int i = 0; i <= loopCount - 1; i++)
+    {
+        pixels[startIndex + i].r = c2.red;
+        pixels[startIndex + i].g = c2.green;
+        pixels[startIndex + i].b = c2.blue;
+
+        pixels[stopIndex - i].r = c2.red;
+        pixels[stopIndex - i].g = c2.green;
+        pixels[stopIndex - i].b = c2.blue;
+
+        _neoPixel.send(pixels, count);
+
+        if (count == 16)
+        {
+            wait(0.05);
+        }
+        else
+        {
+            wait(0.04);
+        }
     }
 }