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.
Diff: main.cpp
- Revision:
- 7:242f14ed9055
- Parent:
- 6:59f1db26a9ff
- Child:
- 8:a179aad4fa2e
--- a/main.cpp Tue Feb 26 02:50:13 2013 +0000 +++ b/main.cpp Tue Feb 26 02:54:44 2013 +0000 @@ -37,50 +37,7 @@ 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" - );**/ + led_strip_write_color(colors++, gpio.reg_set, gpio.reg_clr, gpio.mask); if (interruptFriendly) { @@ -89,8 +46,8 @@ __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. + __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. } } @@ -98,7 +55,7 @@ using namespace Pololu; DigitalOut myled(LED1); -PololuLedStrip ledStrip(LED1); +PololuLedStrip ledStrip(p8); DigitalOut myled2(LED2); @@ -111,7 +68,7 @@ while(1) { myled2 = !myled2.read(); - led_strip_write_color(colors, gpio.reg_set, gpio.reg_clr, gpio.mask); - wait(0.2); + ledStrip.write(colors, LED_COUNT); + wait_ms(200); } }