Hey guys. I've been beating my head against the wall trying to figure this out. I've been working with APA102 LEDs and in my venture, I've seen some pretty cool things that can be done with them. I have them working just fine with a PICAXE 20x2 but one of the things I'm struggling with is getting them to fade from one color to the next while giving the appearance of pushing the first color down the line. I have it working with the following code but it takes a lot of code to make it happen for only 10 LEDs. The project I have in mind is going to have hundreds of these APA102 LEDs so I need to find a better way of doing what I have below. Any tips and advice would be great.
Code:
#picaxe 20x2
'Set how many LED modules
Symbol HOW_MANY_LEDS = 10
symbol RED = w10
symbol GREEN = w11
symbol BLUE = w12
'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
PowerOnReset:
'Initialise the HSPI interface
init
'Turn all LED modules off
head
for w0 = 1 To HOW_MANY_LEDS
send( $00, $00, $00 ) '1 to last = Off
next
head
main:
for b0 = 1 to HOW_MANY_LEDS
select case b0
case 1
head
send( 255, 000, 003 )
head
case 2
head
send( 227, 000, 031 )
send( 255, 000, 003 )
head
case 3
head
send( 199, 000, 059 )
send( 227, 000, 031 )
send( 255, 000, 003 )
head
case 4
head
send( 171, 000, 087 )
send( 199, 000, 059 )
send( 227, 000, 031 )
send( 255, 000, 003 )
head
case 5
head
send( 143, 000, 115 )
send( 171, 000, 087 )
send( 199, 000, 059 )
send( 227, 000, 031 )
send( 255, 000, 003 )
head
case 6
head
send( 115, 000, 143 )
send( 143, 000, 115 )
send( 171, 000, 087 )
send( 199, 000, 059 )
send( 227, 000, 031 )
send( 255, 000, 003 )
head
case 7
head
send( 087, 000, 171 )
send( 115, 000, 143 )
send( 143, 000, 115 )
send( 171, 000, 087 )
send( 199, 000, 059 )
send( 227, 000, 031 )
send( 255, 000, 003 )
head
case 8
head
send( 059, 000, 199 )
send( 087, 000, 171 )
send( 115, 000, 143 )
send( 143, 000, 115 )
send( 171, 000, 087 )
send( 199, 000, 059 )
send( 227, 000, 031 )
send( 255, 000, 003 )
head
case 9
head
send( 031, 000, 227 )
send( 059, 000, 199 )
send( 087, 000, 171 )
send( 115, 000, 143 )
send( 143, 000, 115 )
send( 171, 000, 087 )
send( 199, 000, 059 )
send( 227, 000, 031 )
send( 255, 000, 003 )
head
case 10
head
send( 003, 000, 255 )
send( 031, 000, 227 )
send( 059, 000, 199 )
send( 087, 000, 171 )
send( 115, 000, 143 )
send( 143, 000, 115 )
send( 171, 000, 087 )
send( 199, 000, 059 )
send( 227, 000, 031 )
send( 255, 000, 003 )
head
end select
pause 100
next