Library and demo using the WS2812-based Neopixel strip connected to an LPC114

Dependencies:   mbed

Fork of LEDTape_WS2812 by Suga koubou

Details here: http://mbed.org/users/rhodes42/notebook/tiny-neopixel-controller-with-lpc1114/

Files at this revision

API Documentation at this revision

Comitter:
rhodes42
Date:
Mon Mar 24 10:00:54 2014 +0000
Parent:
1:71b32479b674
Child:
3:743570d993aa
Commit message:
Working demo shifting Red Green & Blue

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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LEDStripFunctions.cpp	Mon Mar 24 10:00:54 2014 +0000
@@ -0,0 +1,54 @@
+#include "mbed.h"
+#include "LEDStrip.h"
+#include <stdint.h>
+
+
+void setAll(uint32_t *buffer, int n)
+{
+    int i;
+    for (i = 0; i < n; i++)
+    {
+        tapeSet(i, buffer[i]);   
+    }
+}
+
+void setAllOneColor(uint32_t color, int n)
+{
+    int i;
+    for (i = 0; i < n; i++)
+    {
+        tapeSet(i, color);   
+    }   
+}
+
+void shiftAllFwd(uint32_t *buffer, int n)
+{
+    int i;
+    uint32_t temp = buffer[n];
+    for (i = n; i > 0; i--)
+    {        
+        buffer[i] = buffer[i-1];
+    }
+    buffer[0] = temp;
+}
+
+void shiftAllRev(uint32_t *buffer, int n)
+{
+    int i;
+    uint32_t temp = buffer[0];
+    for (i = 0; i <= n-1; i++)
+    {        
+        buffer[i] = buffer[i+1];
+    }
+    buffer[n] = temp;
+}
+
+
+void setEveryMod(uint32_t * buffer, uint32_t color, int mod, int start, int n)
+{
+    int i;
+    for (i = 0; i < n; i ++)
+    {
+        if ((i >= start) && ((i - start) % mod == 0)) buffer[i] = color;   
+    }   
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LEDStripFunctions.h	Mon Mar 24 10:00:54 2014 +0000
@@ -0,0 +1,8 @@
+
+#include <stdint.h>
+
+void setAll(uint32_t *buffer, int n);
+void setAllOneColor(uint32_t color, int n);
+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);
--- a/main.cpp	Mon Mar 24 08:06:29 2014 +0000
+++ b/main.cpp	Mon Mar 24 10:00:54 2014 +0000
@@ -4,6 +4,7 @@
 #include "mbed.h"
 #include "LEDStrip.h"
 #include <stdint.h>
+#include "LEDStripFunctions.h"
 
 //Serial pc(USBTX, USBRX);
 DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4);
@@ -26,179 +27,37 @@
    // pc.printf("led\r\n");
     int color_on = (0xff << 16) | (0xff << 8) | (0xff);
 
+    uint32_t colors[numLEDs];
+    /*
+    for (k = 0; k < numLEDs; k++)
+    {
+        colors[k] = (k*260000);
+    }*/
+    
+    setEveryMod(colors, 0xff, 3, 0, numLEDs);
+    setEveryMod(colors, (0xff<<8), 3, 1, numLEDs);
+    setEveryMod(colors, (0xff<<16), 3, 2, numLEDs);
+    
+
     for (;;) {
-      //  for (i = 0; i < 256; i ++) {
-            led1 = 1;
+            led1 = 1;           
             
-            /*
-            for(k = 0; k < 59; k += 2)
-            {
-                tapeSet(k, color_on);    
-            }
-            for(k = 1; k < 59; k += 2)
-            {
-                tapeSet(k, 0);    
-            }
-            tapeSend();
-            led2 = 0;
-            wait_ms(1000);
+            
             
-            for(k = 0; k < 59; k += 2)
-            {
-                tapeSet(k, 0);    
-            }
-            for(k = 1; k < 59; k += 2)
-            {
-                tapeSet(k, color_on);    
-            }
-            tapeSend();
-            wait_ms(1000);
-            */
-            
-            for(i = 0; i < 255; i++);
+            for(i = 0; i < 59; i++);
             {
-                color_on = (i << 16) | (i << 8) | (i);
-                //led2 = 1;
-                /*
-                for(j = 0; j < numLEDs; j++);
-                { 
-                    tapeSet(j, color_on);
-                }*/
-                //tapeSet(k, 0);    
-                tapeSet(0,0);                
-                tapeSet(1,color_on);                
-                tapeSet(2,0);                
-                tapeSet(3,color_on);                
-                tapeSet(4,0);  
-                tapeSet(5,color_on);                
-                tapeSet(6,0);                
-                tapeSet(7,color_on);                
-                tapeSet(8,0);                
-                tapeSet(9,color_on);
-                tapeSet(10,0);                
-                tapeSet(11,color_on);                
-                tapeSet(12,0);                
-                tapeSet(13,color_on);                
-                tapeSet(14,0);
-                tapeSet(15,color_on);                
-                tapeSet(16,0);                
-                tapeSet(17,color_on);                
-                tapeSet(18,0);                
-                tapeSet(19,color_on);   
-                tapeSet(20,0);                
-                tapeSet(21,color_on);                
-                tapeSet(22,0);                
-                tapeSet(23,color_on);                
-                tapeSet(24,0);
-                tapeSet(25,color_on);                
-                tapeSet(26,0);                
-                tapeSet(27,color_on);                
-                tapeSet(28,0);                
-                tapeSet(29,color_on);   
-                tapeSet(30,0);                
-                tapeSet(31,color_on);                
-                tapeSet(32,0);                
-                tapeSet(33,color_on);                
-                tapeSet(34,0);
-                tapeSet(35,color_on);                
-                tapeSet(36,0);                
-                tapeSet(37,color_on);                
-                tapeSet(38,0);                
-                tapeSet(39,color_on);   
-                tapeSet(40,0);                
-                tapeSet(41,color_on);                
-                tapeSet(42,0);                
-                tapeSet(43,color_on);                
-                tapeSet(44,0);
-                tapeSet(45,color_on);                
-                tapeSet(46,0);                
-                tapeSet(47,color_on);                
-                tapeSet(48,0);                
-                tapeSet(49,color_on);    
-                tapeSet(50,0);                
-                tapeSet(51,color_on);                
-                tapeSet(52,0);                
-                tapeSet(53,color_on);                
-                tapeSet(54,0);
-                tapeSet(55,color_on);                
-                tapeSet(56,0);                
-                tapeSet(57,color_on);                
-                tapeSet(58,0);      
                 
+                shiftAllFwd(colors, numLEDs);   
+                setAll(colors, numLEDs);
                 led1 = 0;
                 tapeSend();
-                wait_ms(50);
-                
-                /*
-                for(j = 0; j < numLEDs; j++);
-                { 
-                    tapeSet(j, 0);
-                }*/
-                //tapeSet(k, color_on);
+                wait_ms(100);
                 
-                tapeSet(0,color_on);                
-                tapeSet(1,0);                
-                tapeSet(2,color_on);                
-                tapeSet(3,0);                
-                tapeSet(4,color_on);  
-                tapeSet(5,0);                
-                tapeSet(6,color_on);                
-                tapeSet(7,0);                
-                tapeSet(8,color_on);                
-                tapeSet(9,0);
-                tapeSet(10,color_on);                
-                tapeSet(11,0);                
-                tapeSet(12,color_on);                
-                tapeSet(13,0);                
-                tapeSet(14,color_on);
-                tapeSet(15,0);                
-                tapeSet(16,color_on);                
-                tapeSet(17,0);                
-                tapeSet(18,color_on);                
-                tapeSet(19,0);   
-                tapeSet(20,color_on);                
-                tapeSet(21,0);                
-                tapeSet(22,color_on);                
-                tapeSet(23,0);                
-                tapeSet(24,color_on);
-                tapeSet(25,0);                
-                tapeSet(26,color_on);                
-                tapeSet(27,0);                
-                tapeSet(28,color_on);                
-                tapeSet(29,0);   
-                tapeSet(30,color_on);                
-                tapeSet(31,0);                
-                tapeSet(32,color_on);                
-                tapeSet(33,0);                
-                tapeSet(34,color_on);
-                tapeSet(35,0);                
-                tapeSet(36,color_on);                
-                tapeSet(37,0);                
-                tapeSet(38,color_on);                
-                tapeSet(39,0);   
-                tapeSet(40,color_on);                
-                tapeSet(41,0);                
-                tapeSet(42,color_on);                
-                tapeSet(43,0);                
-                tapeSet(44,color_on);
-                tapeSet(45,0);                
-                tapeSet(46,color_on);                
-                tapeSet(47,0);                
-                tapeSet(48,color_on);                
-                tapeSet(49,0);    
-                tapeSet(50,color_on);                
-                tapeSet(51,0);                
-                tapeSet(52,color_on);                
-                tapeSet(53,0);                
-                tapeSet(54,color_on);
-                tapeSet(55,0);                
-                tapeSet(56,color_on);                
-                tapeSet(57,0);                
-                tapeSet(58,color_on);      
+                shiftAllFwd(colors, numLEDs);                
+                setAll(colors, numLEDs);
                 led1 = 1;
                 tapeSend();
-                wait_ms(50);
+                wait_ms(100);
             }
-     //  }
     }
 }