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

Dependencies:   PololuLedStrip mbed LedStripGradient

Dependents:   LedStripGradient led_phare_crf

For more information, see the PololuLedStrip library.

Files at this revision

API Documentation at this revision

Comitter:
DavidEGrayson
Date:
Tue Feb 26 03:12:26 2013 +0000
Parent:
7:242f14ed9055
Child:
9:b1c530cad69b
Commit message:
First attempt at a gradient pattern. Tested only on the oscilloscope.

Changed in this revision

led_strip.s 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
--- a/led_strip.s	Tue Feb 26 02:54:44 2013 +0000
+++ b/led_strip.s	Tue Feb 26 03:12:26 2013 +0000
@@ -1,8 +1,9 @@
     AREA asm_func, CODE, READONLY
-    EXPORT led_strip_write_color   
+    EXPORT led_strip_write_color
+
 led_strip_write_color
     push    {r12, r7}
-    
+   
     ldr r12, [r0]      ; Read the next color.
     rbit r12, r12      ; Reverse the order of the bits.
     rev r12, r12       ; Reverse the order of the bytes.
--- a/main.cpp	Tue Feb 26 02:54:44 2013 +0000
+++ b/main.cpp	Tue Feb 26 03:12:26 2013 +0000
@@ -1,74 +1,81 @@
-#include "mbed.h"
-#include "gpio_api.h"
-
-namespace Pololu
-{
-  #ifndef _POLOLU_RGB_COLOR
-  #define _POLOLU_RGB_COLOR
-  typedef struct rgb_color
-  {
-    uint8_t red, green, blue;
-  } rgb_color;
-  #endif
-
-  extern "C" int led_strip_write_color(rgb_color *, volatile uint32_t * set, volatile uint32_t * clear, uint32_t mask);
-
-  class PololuLedStrip
-  {
-    static bool interruptFriendly;
-    public:
-    gpio_t gpio;
-    PololuLedStrip(PinName pin);
-    void write(rgb_color * colors, unsigned int count);
-  };
-
-  bool PololuLedStrip::interruptFriendly;
-
-  PololuLedStrip::PololuLedStrip(PinName pinName)
-  {
-    gpio_init(&gpio, pinName, PIN_OUTPUT);
-  }
-
-  void PololuLedStrip::write(rgb_color * colors, unsigned int count)
-  {
-    uint32_t pinValue = gpio.pin & 0x1F;  // Mimicing mbed/libraries/mbed/vendor/NXP/capi/gpio_api.c
-    
-    __disable_irq();   // Disable interrupts temporarily because we don't want our pulse timing to be messed up.
-    
-    while(count--)
-    {
-      led_strip_write_color(colors++, gpio.reg_set, gpio.reg_clr, gpio.mask);
-      
-      if (interruptFriendly)
-      {
-        __enable_irq();
-        //asm volatile("nop\n");
-        __disable_irq();
-      }
-    }
-    __enable_irq();   // Re-enable interrupts now that we are done.
-    wait_us(24);      // Hold the line low for 24 microseconds to send the reset signal.
-  }
-
-}
-
-using namespace Pololu;
-
-DigitalOut myled(LED1);
-PololuLedStrip ledStrip(p8);
-
-DigitalOut myled2(LED2);
-
-#define LED_COUNT 60
-rgb_color colors[LED_COUNT];
-
-int main() {
-    gpio_t gpio;
-    gpio_init(&gpio, p8, PIN_OUTPUT);
-
-    while(1) {
-        myled2 = !myled2.read();
-        ledStrip.write(colors, LED_COUNT);
-        wait_ms(200);
-    }
-}
+#include "mbed.h"
+
+namespace Pololu
+{
+    #ifndef _POLOLU_RGB_COLOR
+    #define _POLOLU_RGB_COLOR
+    typedef struct rgb_color
+    {
+        uint8_t red, green, blue;
+    } rgb_color;
+    #endif
+
+    extern "C" int led_strip_write_color(rgb_color *, volatile uint32_t * set, volatile uint32_t * clear, uint32_t mask);
+
+    class PololuLedStrip
+    {
+        static bool interruptFriendly;
+        public:
+        gpio_t gpio;
+        PololuLedStrip(PinName pin);
+        void write(rgb_color * colors, unsigned int count);
+    };
+
+    bool PololuLedStrip::interruptFriendly;
+
+    PololuLedStrip::PololuLedStrip(PinName pinName)
+    {
+       gpio_init(&gpio, pinName, PIN_OUTPUT);
+    }
+
+    void PololuLedStrip::write(rgb_color * colors, unsigned int count)
+    {
+        __disable_irq();   // Disable interrupts temporarily because we don't want our pulse timing to be messed up.
+    
+        while(count--)
+        {
+            led_strip_write_color(colors++, gpio.reg_set, gpio.reg_clr, gpio.mask);
+      
+            if (interruptFriendly)
+            {
+                __enable_irq();
+                __nop();
+                __nop();
+                __nop();
+                __disable_irq();
+            }
+        }
+        __enable_irq();   // Re-enable interrupts now that we are done.
+        wait_us(24);      // Hold the line low for 24 microseconds to send the reset signal.
+    }
+}
+
+using namespace Pololu;
+
+#define LED_COUNT 60
+rgb_color colors[LED_COUNT];
+
+PololuLedStrip ledStrip(p8);
+
+DigitalOut led2(LED2);
+
+Timer timer;
+
+int main()
+{
+    timer.start();
+
+    while(1)
+    {
+        uint8_t time = timer.read_ms() >> 2;
+        for(uint8_t i = 0; i < LED_COUNT; i++)
+        {
+            uint8_t x = time - 8*i;
+            colors[i] = (rgb_color){ x, 255 - x, x };
+        }
+    
+        led2 = !led2.read();
+        ledStrip.write(colors, LED_COUNT);
+        wait_ms(10);
+    }
+}