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.

Revision:
1:ac1550d65296
Parent:
0:290d713ed3e1
Child:
2:bd6fe6d2948d
--- a/main.cpp	Tue Feb 26 01:49:34 2013 +0000
+++ b/main.cpp	Tue Feb 26 02:04:07 2013 +0000
@@ -1,113 +1,118 @@
-#include "mbed.h"
-#include "gpio_api.h"
-
-extern "C" int my_asm(int value);
-
-namespace Pololu
-{
-  #ifndef _POLOLU_RGB_COLOR
-  #define _POLOLU_RGB_COLOR
-  typedef struct rgb_color
-  {
-    uint8_t red, green, blue;
-  } rgb_color;
-  #endif
-
-  class PololuLedStrip
-  {
-    static bool interruptFriendly;
-    public:
-    gpio_t gpio;
-    PololuLedStrip(PinName pin);
-    void write(rgb_color *, 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--)
-    {
-    /**
-      // Send a color to the LED strip.
-      // The assembly below also increments the 'colors' pointer,
-      // it will be pointing to the next color at the end of this loop.
-      __ASM volatile(
-        "ldr r12, [%0], #3\n"   // Read the next color and advance the pointer.
-        "rbit r12, r12\n"       // Reverse the order of the bits.
-        "rev r12, r12\n"        // Reverse the order of the bytes.
-        "mov r3, #24\n"         // Initialize the loop counter register.
-
-        "send_led_strip_bit%=:\n"
-        "str %[val], %[set]\n"            // Drive the line high.
-        "rrxs r12, r12\n"                 // Rotate right through carry.
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n"
-        "it cc\n" "strcc %[val], %[clear]\n"  // If the bit to send is 0, set the line low now.
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "it cs\n" "strcs %[val], %[clear]\n"  // If the bit to send is 1, set the line low now.
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-
-        "sub r3, r3, #1\n"                // Decrement the loop counter.
-        "cbz r3, led_strip_asm_end%=\n"   // If we have sent 24 bits, go to the end.
-        "b send_led_strip_bit%=\n"
-        
-        "led_strip_asm_end%=:\n"
-
-      : "=r" (colors)
-      : "0" (colors),
-        [set] "m" (gpio.reg_set),
-        [clear] "m" (gpio.reg_clr),
-        [val] "r" (pinValue)
-      : "r3", "r12", "cc"
-      );**/
-      
-      if (interruptFriendly)
-      {
-        __enable_irq();
-        //asm volatile("nop\n");
-        __disable_irq();
-      }
-    }
-    __enable_irq();          // Re-enable interrupts now that we are done.
-    //delayMicroseconds(24);  // Hold the line low for 24 microseconds to send the reset signal.
-  }
-
-}
-
-using namespace Pololu;
-
-DigitalOut myled(LED1);
-
-PololuLedStrip ledStrip(p9);
-
-int main() {
-    while(1) {
-        //myled = 1;
-        my_asm(1);
-        wait(0.2);
-        my_asm(0);
-        //myled = 0;
-        wait(1);
-    }
-}
+#include "mbed.h"
+#include "gpio_api.h"
+
+//extern "C" int my_asm(volatile uint32_t * set, int value);
+extern "C" int my_asm(int x, int value);
+
+namespace Pololu
+{
+  #ifndef _POLOLU_RGB_COLOR
+  #define _POLOLU_RGB_COLOR
+  typedef struct rgb_color
+  {
+    uint8_t red, green, blue;
+  } rgb_color;
+  #endif
+
+  class PololuLedStrip
+  {
+    static bool interruptFriendly;
+    public:
+    gpio_t gpio;
+    PololuLedStrip(PinName pin);
+    void write(rgb_color *, 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--)
+    {
+    /**
+      // Send a color to the LED strip.
+      // The assembly below also increments the 'colors' pointer,
+      // it will be pointing to the next color at the end of this loop.
+      __ASM volatile(
+        "ldr r12, [%0], #3\n"   // Read the next color and advance the pointer.
+        "rbit r12, r12\n"       // Reverse the order of the bits.
+        "rev r12, r12\n"        // Reverse the order of the bytes.
+        "mov r3, #24\n"         // Initialize the loop counter register.
+
+        "send_led_strip_bit%=:\n"
+        "str %[val], %[set]\n"            // Drive the line high.
+        "rrxs r12, r12\n"                 // Rotate right through carry.
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n"
+        "it cc\n" "strcc %[val], %[clear]\n"  // If the bit to send is 0, set the line low now.
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "it cs\n" "strcs %[val], %[clear]\n"  // If the bit to send is 1, set the line low now.
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+
+        "sub r3, r3, #1\n"                // Decrement the loop counter.
+        "cbz r3, led_strip_asm_end%=\n"   // If we have sent 24 bits, go to the end.
+        "b send_led_strip_bit%=\n"
+        
+        "led_strip_asm_end%=:\n"
+
+      : "=r" (colors)
+      : "0" (colors),
+        [set] "m" (gpio.reg_set),
+        [clear] "m" (gpio.reg_clr),
+        [val] "r" (pinValue)
+      : "r3", "r12", "cc"
+      );**/
+      
+      if (interruptFriendly)
+      {
+        __enable_irq();
+        //asm volatile("nop\n");
+        __disable_irq();
+      }
+    }
+    __enable_irq();          // Re-enable interrupts now that we are done.
+    //delayMicroseconds(24);  // Hold the line low for 24 microseconds to send the reset signal.
+  }
+
+}
+
+using namespace Pololu;
+
+DigitalOut myled(LED1);
+DigitalOut myled2(LED2);
+
+PololuLedStrip ledStrip(p9);
+
+int main() {
+    gpio_t gpio;
+    gpio_init(&gpio, LED1, PIN_OUTPUT);
+
+    while(1) {
+        myled2 = 1;
+        my_asm(1, 1);
+        wait(0.2);
+        my_asm(0, 0);
+        myled2 = 0;
+        wait(1);
+    }
+}