techElder
Well-known member
I think its interesting. In the original post here with APA102 strip examples, there came some confusion on my part in understanding the code.
I'm building a project with a 1 meter strip of 144 LEDs. The main idea is to show a number as a bar of a certain percentage of the 144 LEDs in the strip. I kept running into problems with unexplained delays in the example code. I finally figured it out. Over exuberance!
I found this situation replicated in many code examples.
The key is to send the colors for each LED in sequence, one-at-a-time. That means repeating that process to HOW_MANY_LEDS (144 in my case). The over exuberance came in when the multicolor idea came into the process with different colors for 7 LEDs in a group. Now we're sending a group of 7 LEDs information HOW_MANY_LEDS times! There is a lot of extra delay to do that, so timing is extended greatly. (Yes, I understand that any additional is just running out the end into the bit bucket!
)
The fix is to change the FOR/NEXT loop to STEP 7 for the group of LEDs (6 in my case.) Now the FOR/NEXT count will keep up with HOW_MANY_LEDS. This also means that one has to match the LEDs in the group with HOW_MANY_LEDS so there is an integer division.
Here's a little diddy that came from the examples with a simple addition that makes it work as originally designed.
I'm building a project with a 1 meter strip of 144 LEDs. The main idea is to show a number as a bar of a certain percentage of the 144 LEDs in the strip. I kept running into problems with unexplained delays in the example code. I finally figured it out. Over exuberance!
The key is to send the colors for each LED in sequence, one-at-a-time. That means repeating that process to HOW_MANY_LEDS (144 in my case). The over exuberance came in when the multicolor idea came into the process with different colors for 7 LEDs in a group. Now we're sending a group of 7 LEDs information HOW_MANY_LEDS times! There is a lot of extra delay to do that, so timing is extended greatly. (Yes, I understand that any additional is just running out the end into the bit bucket!
The fix is to change the FOR/NEXT loop to STEP 7 for the group of LEDs (6 in my case.) Now the FOR/NEXT count will keep up with HOW_MANY_LEDS. This also means that one has to match the LEDs in the group with HOW_MANY_LEDS so there is an integer division.
Here's a little diddy that came from the examples with a simple addition that makes it work as originally designed.
Code:
#picaxe 20x2
#no_table
#no_data
; =======================================================
; Example 7
; Set all LED modules on
; =======================================================
; 40X2 5V -.- Light strip
; .-----__-----. |
; | RST B.7 | `--> RED +V
; = = .--> SCK --------> BLU CK
; | C.2 C.5 |--|--> SDO --------> GRN DI
; .--| C.3 C.4 | | .--> YEL 0V
; | | D.0 D.3 | | |
; | | D.1 D.2 | | 0V _|_
; | `------------' |
; `------------------'
; Set how many LED modules in the strip
Symbol HOW_MANY_LEDS = 144 '147/7
; Set the brightness of the LED while testing
; Use small values to keep current consumption low
Symbol BRIGHTNESS = 10 ; 0 to 255 (full)
; Initialise the HSPI interface
#macro init()
hspisetup spimode00, spifast
#endmacro
; Send a four byte packet out via HSPI
#macro sendPacket( n1, n2, n3, n4 )
hspiout( n1, n2, n3, n4 )
#endmacro
; Send the start of data header
#macro head()
sendPacket( $00, $00, $00, $00 )
#endmacro
; Send a LED controlling command
#macro send( red, green, blue)
sendPacket( $FF, blue, green, red )
#endmacro
; Send the end of data tail
#macro tail()
sendPacket( $FF, $FF, $FF, $FF )
'sendPacket( $FF, $FF, $FF, $FF )
'sendPacket( $FF, $FF, $FF, $FF )
#endmacro
PowerOnReset:
; Initialise the HSPI interface
init
TurnAllLedsOn:
; Turn all LED modules on
do
head
for w0 = 1 to HOW_MANY_LEDS step 6
send( BRIGHTNESS, $00, $00 ) ; red
send( $00, BRIGHTNESS, $00 ) ; green
send( $00, $00, BRIGHTNESS ) ; blue
send( BRIGHTNESS, BRIGHTNESS, $00 ) ; red + green
send( BRIGHTNESS, $00, BRIGHTNESS ) ; red + blue
send( $00, BRIGHTNESS, BRIGHTNESS ) ; green + blue
'send( BRIGHTNESS, BRIGHTNESS, BRIGHTNESS ) ; white
pause 50
next
tail
head
for w0 = 1 to HOW_MANY_LEDS step 6
send( BRIGHTNESS, $00, $00 ) ; red
send( BRIGHTNESS, $00, $00 ) ; red
send( BRIGHTNESS, $00, $00 ) ; red
send( BRIGHTNESS, $00, $00 ) ; red
send( BRIGHTNESS, $00, $00 ) ; red
send( BRIGHTNESS, $00, $00 ) ; red
'send( BRIGHTNESS, $00, $00 ) ; red
pause 50
next
tail
head
for w0 = 1 to HOW_MANY_LEDS step 6
send( $00, BRIGHTNESS, $00 ) ; green
send( $00, BRIGHTNESS, $00 ) ; green
send( $00, BRIGHTNESS, $00 ) ; green
send( $00, BRIGHTNESS, $00 ) ; green
send( $00, BRIGHTNESS, $00 ) ; green
send( $00, BRIGHTNESS, $00 ) ; green
'send( $00, BRIGHTNESS, $00 ) ; green
pause 50
next
tail
head
for w0 = 1 to HOW_MANY_LEDS step 6
send( $00, $00, BRIGHTNESS ) ; blue
send( $00, $00, BRIGHTNESS ) ; blue
send( $00, $00, BRIGHTNESS ) ; blue
send( $00, $00, BRIGHTNESS ) ; blue
send( $00, $00, BRIGHTNESS ) ; blue
send( $00, $00, BRIGHTNESS ) ; blue
'send( $00, $00, BRIGHTNESS ) ; blue
pause 50
next
tail
head
for w0 = 1 to HOW_MANY_LEDS step 6
send( $00, $00, $00) ; black
send( $00, $00, $00) ; black
send( $00, $00, $00) ; black
send( $00, $00, $00) ; black
send( $00, $00, $00) ; black
send( $00, $00, $00) ; black
'send( $00, $00, $00) ; black
pause 50
next
tail
loop