This is an example program for the PololuLedStrip library. It generates a simple moving rainbow pattern.

Dependencies:   PololuLedStrip mbed

For more information, see the PololuLedStrip library.

Revision:
0:a3a9c486fc68
Child:
1:3d89bcd21002
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Feb 27 02:45:50 2013 +0000
@@ -0,0 +1,50 @@
+#include "mbed.h"
+#include "PololuLedStrip.h"
+
+PololuLedStrip ledStrip(p8);
+
+#define LED_COUNT 60
+rgb_color colors[LED_COUNT];
+
+Timer timer;
+
+// Converts a color from the HSV representation to RGB.
+rgb_color hsvToRgb(float h, float s, float v)
+{
+    int i = floor(h * 6);
+    float f = h * 6 - i;
+    float p = v * (1 - s);
+    float q = v * (1 - f * s);
+    float t = v * (1 - (1 - f) * s);
+    float r, g, b;
+    switch(i % 6){
+        case 0: r = v; g = t; b = p; break;
+        case 1: r = q; g = v; b = p; break;
+        case 2: r = p; g = v; b = t; break;
+        case 3: r = p; g = q; b = v; break;
+        case 4: r = t; g = p; b = v; break;
+        case 5: r = v; g = p; b = q; break;
+    }
+    return (rgb_color){r * 255, g * 255, b * 255};
+}
+
+int main()
+{
+    timer.start();
+
+    while(1)
+    {
+        uint32_t time = timer.read_ms();
+        
+        // Update the colors array.
+        for(int i = 0; i < LED_COUNT; i++)
+        {
+            uint8_t phase = (time >> 4) - (i << 2);
+            colors[i] = hsvToRgb(phase / 256.0, 1.0, 1.0);
+        }
+    
+        // Send the colors to the LED strip.
+        ledStrip.write(colors, LED_COUNT);
+        wait_ms(10);
+    }
+}