The E12 resistor series (10% tolerance) has values of 1.0, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2 and 10.0 times a power of ten. Each number is chosen so that 10% high on the lower nominal value is about equal to 10% low on the next nominal value).... hard to find 20 k resistor
No. A 10MHz resonator will give a 40MHz operating speed.If I used a 40x2 or 28x2 with a 10 mhz res would it be faster then a 20x2 with setfreq m64 ?
from hippyIt doesn't seem it has to be small if using a PC power supply.
Not sure if you're saying that the .sch file didn't work when sent to oshpark, or didn't work when loaded into Eagle. If the former, that's as expected--they take .brd files (because the schematic file doesn't tell them anything about the physical placement of the components and their connections). If it won't load into Eagle, I'll look into the problem.the file 20sip.sch wouldn't work but .brd did ..FYI
#picaxe 20X2 ' I am using 20x2 and have the hspi clk/hspi sdo connected correctly
#no_table
#no_data
setfreq m16
Symbol HOW_MANY_LEDS = 150
Symbol HOW_MANY_LEDS_MINUS_1 = HOW_MANY_LEDS - 1
; Set the brightness of the LED while testing
; Use small values to keep current consumption low
Symbol BRIGHTNESS = 5 ; 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 )
#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
tail
BounceLed:
; Set one LED at a time
; 'w0' indicates which LED to set
do
head
for w0 = 1 to HOW_MANY_LEDS
send( BRIGHTNESS, $00, $00 ) ; red
pause 10
next
tail
for w0 = HOW_MANY_LEDS_MINUS_1 to 1 step -1
Gosub SetLed
next
loop
SetLed:
; Set a specific LED and keep the others off
head
for w1 = 1 to HOW_MANY_LEDS
if w1<w0 then send( BRIGHTNESS, $00, $00 ) ; red
elseif w0<HOW_MANY_LEDS then send( $00, $00, $00 ) ; red
endif
next
tail
return
#macro head()
sendPacket( $00, $00, $00, $00 )
#endmacro
head
for w0 = 1 to HOW_MANY_LEDS
send( BRIGHTNESS, $00, $00 ) ; red
pause 10
next
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
tail
; Set one LED at a time
; 'w0' indicates which LED to set
do
for w0 = HOW_MANY_LEDS_MINUS_1 to 1 step -1
Gosub SetLed
next
loop
SetLed:
; Set a specific LED and keep the others off
head
for w1 = 1 to HOW_MANY_LEDS
if w1 = w0 then
send( BRIGHTNESS, $00, $00 ) ; red
else
send( $00, $00, $00 ) ; off
endif
next
tail
return
Part of the confusion is that the code has macros (e.g., send()) using macros (sendPacket()). Nothing wrong with that--it's a good generalization of the code--but it makes it less immediately clear what is happening.where/what does it do with sendpacket ( $00, $00, $00, $00 )
"Options" is the little wrench under "Workspace Explorer".If one selects Options, Diagnostics and ticks the Pre-processor, 'Display pre-processor output' option one can see what the actual code generated will be when the code is Syntax Checked.
That's probably the best way to learn. Once one is familiar with how it works it gets easier to follow how others are using them.I just need a little more practice taking the #macro to fully understand it ... that's the best way i learn anyhow
#macro head()
hspiout ( $00, $00, $00, $00 )
#endmacro
#macro tail()
hspiout ( $FF, $FF, $FF, $FF )
#endmacro
#macro sendPacket( n1, n2, n3, n4 )
hspiout( n1, n2, n3, n4 )
#endmacro
#macro head()
sendPacket( $00, $00, $00, $00 )
#endmacro
#macro tail()
sendPacket( $FF, $FF, $FF, $FF )
#endmacro
#macro tail()
hspiout ( $FF, $FF, $FF, $FF )
#endmacro
'This code is not perfect and is made possible only from help of picaxe forum
;#picaxe 20x2 code uses picaxe 20X2 on single white APA102 led strip (not RGB)
#NO_TABLE ' it has 150 leds and turns one led on after another
#NO_DATA ' so example of 8 leds...10000000-11000000-11100000 etc
' then turns them off in the same way backwards
setfreq m64 '<--- m64 with spislow is faster then m32 with spifast for my code test
Symbol leds_on_or_off = b4
Symbol count1 = b5
Symbol HOW_MANY_LEDS = 150
Symbol LEDS = HOW_MANY_LEDS
Symbol BRIGHTNESS = 10 ; 0 to 255 (full)
START:
hspisetup spimode00, spislow
FOR b0 = 1 to HOW_MANY_LEDS
gosub flow_led
NEXT b0
FOR b0 = HOW_MANY_LEDS to 1 step -1
gosub flow_led
NEXT b0
gosub LEDS_OFF
GOTO START
LEDS_OFF:
hspiout( $00, $00, $00, $00 )
FOR b0 = 1 To HOW_MANY_LEDS ; 1 to last = Off
hspiout( $FF, $00, $00, $00 )
NEXT b0
hspiout( $FF, $FF, $FF, $FF )
RETURN
FLOW_LED:; leds on + leds off needs to = total leds
hspiout( $00, $00, $00, $00 )
FOR leds_on_or_off = 1 to b0
hspiout( $FF, $00, $00, BRIGHTNESS )
NEXT
count1 = LEDS - b0
FOR leds_on_or_off = 1 to count1
hspiout( $FF, $00, $00, $00 )
NEXT
hspiout( $FF, $FF, $FF, $FF )
RETURN
START:
hspisetup spimode00, spislow
FOR b0 = 1 to HOW_MANY_LEDS
gosub flow_led
NEXT b0
FOR b0 = HOW_MANY_LEDS to 1 step -1
gosub flow_led
NEXT b0
gosub LEDS_OFF
GOTO START
START:
hspisetup spimode00, spislow
DO
FOR b0 = 1 to HOW_MANY_LEDS
gosub flow_led
NEXT b0
FOR b0 = HOW_MANY_LEDS to 1 step -1
gosub flow_led
NEXT b0
gosub LEDS_OFF
LOOP
Or, to build on the case with macros, the earlier suggestion of -You may note that the difference between your ON and OFF commands is the last byte in the HSPIOUT command--either BRIGHTNESS or $00. You could generalize this code by defining a byte variable, (e.g., SYMBOL level=b6), and then call a single routine "hspiout( $FF, $00, $00, level )" after setting either "level=BRIGHTNESS" or "level=$00". (I don't have your LED strip, so I am speculating based on your code.)
SetLed:
; Set a specific LED and keep the others off
head
for w1 = 1 to HOW_MANY_LEDS
if w1 = w0 then
send( BRIGHTNESS, $00, $00 ) ; red
else
send( $00, $00, $00 ) ; off
endif
next
tail
#Macro ledOn()
send( BRIGHTNESS, $00, $00 )
#EndMacro
#Macro ledOff()
send( $00, $00, $00 )
#EndMacro
SetLed:
; Set a specific LED and keep the others off
head
for w1 = 1 to HOW_MANY_LEDS
if w1 = w0 then
ledOn
else
ledOff
endif
next
tail
Sort of, but not quite. Each HSPIOUT pushes LED data up the chain and the "tail()" function pushes things further along, and how far along it is pushed depends on the number of four $FF bytes are sent in that "tail()".@ hippy Thanks ..so if a person had 60 per meter led strip and had 5 meter strip they should use "gosub leds_off" 5 times ... makes sense
Could be that this gives an SPI speed which is just too high for the LED strip to handle. I haven't looked in the datasheet to check.If I use setfreq m64 and spifast ....the led strip goes berserk
#picaxe 20x2 'One step closer to final code
#no_table
#no_data
Setfreq m64
Symbol loopA = b1
Symbol loop1 = b2
Symbol count1 = b3
Symbol ptime = 20000
Symbol HOW_MANY_LEDS = 151
Symbol LEDS = HOW_MANY_LEDS
Symbol BRIGHTNESS = 10 ; 0 to 255 (full)
'setup
#macro init()
hspisetup spimode00, spimedium
#endmacro
; Send a four byte packet out via HSPI
#macro sendPacket( n1, n2, n3, n4 )
hspiout( n1, n2, n3, n4 )
#endmacro
#macro send( NOled, NOled1, white)
sendPacket( $FF, NOled, NOled1, white )
#endmacro
; Send the start of data tail
#macro head()
sendpacket($00, $00, $00, $00)
#endmacro
; Send the end of data tail
#macro tail()
sendpacket($FF, $FF, $FF, $FF)
#endmacro
' turn on a led
#Macro ledOn()
send( $00, $00, brightness)
#EndMacro
' turn off a led
#Macro ledOff()
send( $00, $00, $00)
#EndMacro
START:
init
FOR b4 = 0 to 2 ' KICK THE BALL VERY HARD 3 times :)
head
For loopA = 1 to HOW_MANY_LEDS
ledOff
Next
tail
pause 10
NEXT b4
DO
gosub SCROLL_FIRST_LEDS_ON :pause ptime' turns leds ON 1st..2nd..3rd...
gosub SCROLL_FIRST_LEDS_OFF:pause ptime' turns leds OFF 1st..2nd..3rd...
gosub SCROLL_LAST_LEDS_ON :pause ptime' turns leds ON 150th..149th..148th...
gosub SCROLL_LAST_LEDS_OFF :pause ptime' turns leds OFF 150th..149th..148th...
LOOP
SCROLL_FIRST_LEDS_ON:
For loopA = 1 to HOW_MANY_LEDS : b0 = loopA
head
FOR loop1 = 1 to b0
ledOn
NEXT loop1
count1 = LEDS - b0
FOR loop1 = 1 to count1
ledOff
NEXT loop1
tail
NEXT loopA
RETURN
SCROLL_FIRST_LEDS_OFF:
For loopA = 1 to HOW_MANY_LEDS : b0 = loopA
head
FOR loop1 = 1 to b0
ledOff
NEXT
count1 = LEDS - b0
FOR loop1 = 1 to count1
ledOn
NEXT
tail
NEXT loopA
RETURN
SCROLL_LAST_LEDS_ON:
For loopA = HOW_MANY_LEDS to 0 step -1 : b0 = loopA
head
FOR loop1 = b0 to 1 step -1
ledOff
NEXT loop1
count1 = LEDS - b0
FOR loop1 = count1 to 0 step -1
ledOn
NEXT loop1
tail
NEXT loopA : gosub ADD_BTYE
RETURN
SCROLL_LAST_LEDS_OFF:
For loopA = HOW_MANY_LEDS to 0 step -1 : b0 = loopA
head
FOR loop1 = b0 to 1 step -1
ledOn
NEXT
count1 = LEDS - b0
FOR loop1 = 0 to count1
ledOff
NEXT
tail
NEXT loopA : gosub DEC_BTYE
RETURN
ADD_BTYE: 'makes so all leds are on ...if I dont use this gosub then last led don't light
FOR b4 = 0 to 2
head
For loop1 = 1 to HOW_MANY_LEDS
ledOn
Next
tail
pause 10
NEXT b4
RETURN
DEC_BTYE:
FOR b4 = 0 to 2 'makes all the leds turn off...if I dont use this gosub then last led stays lit
head
For loop1 = 1 to HOW_MANY_LEDS
ledOff
Next
tail
pause 10
NEXT b4
RETURN
#macro sendPacket( n1, n2, n3, n4 )
hspiout( n1, n2, n3, n4 )
#endmacro
Yes, $FF bytes in tail() not $00 bytes. I have corrected the earlier post. What you want is something like ...Hippy I really like your kicking the ball example makes it simple and I suppose you mean send more $FF bytes in "tail" or just meaning more bytes in general and i understand
#macro tail()
sendPacket( $FF, $FF, $FF, $FF )
sendPacket( $FF, $FF, $FF, $FF )
sendPacket( $FF, $FF, $FF, $FF )
#endmacro
Those are just arbitrary parameter names as with other macros.what i don't understand is
n1,n2...?Code:#macro sendPacket( n1, n2, n3, n4 ) hspiout( n1, n2, n3, n4 ) #endmacro
n1,n2...?Code:#macro sendPacket( n1, n2, n3, n4 ) hspiout( n1, n2, n3, n4 ) #endmacro
To elaborate further, n1, etc. are like placeholders, which are replaced by your real parameters when the macro code is expanded and executed.Those are just arbitrary parameter names as with other macros.
#picaxe 20x2
#no_table
#no_data
; Set how many LED modules in the strip
symbol HOW_MANY_LEDS = 151
; Set the brightness of the LED while testing
; Use small values to keep current consumption low
symbol BRIGHTNESS = 1 ; 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 ) ; 1-64
sendPacket( $FF, $FF, $FF, $FF ) ; 65-128
sendPacket( $FF, $FF, $FF, $FF ) ; 129-192
#endmacro
; Turn a single LED off
#macro ledOff
send( $00, $00, $00 )
#endmacro
; Turn a single LED on
#macro ledOn
send( BRIGHTNESS, $00, $00 )
#endmacro
PowerOnReset:
; Initialise the HSPI interface
init
do
gosub AllOff ; Turn all LEDs off
pause 2000
gosub AllOn ; Turn all LEDs on
pause 2000
loop
AllOff:
head
for w0 = 1 to HOW_MANY_LEDS
ledOff
next
tail
return
AllOn:
head
for w0 = 1 to HOW_MANY_LEDS
ledOn
next
tail
return
gosub SCROLL_FIRST_LEDS_ON :pause ptime' turns leds ON 1st..2nd..3rd...
do
gosub AllOff ; Turn all LEDs off
pause 20000 '2000
do
gosub AllOff ; Turn all LEDs off
pause 2000
pause 2000
pause 2000
pause 2000
pause 2000
pause 2000
pause 2000
pause 2000
pause 2000
pause 2000
gosub AllOff ; Turn all LEDs off
pause 2000
gosub AllOn ; Turn all LEDs on
pause 20000
It's really just substitution ...so how does it change "n1" into "$ff" ... probably real simple, but probably thinking to deep again
#Macro Hello( whoever )
SerTxd( "Hello ", whoever, CR, LF )
#EndMacro
Hello( "Tom" )
Hello( "Dick" )
Hello( "Harry" )
It is best to set the symbol to the number of LEDs you actually have. If that doesn't work then fix it how it should be fixed because bodging it to work can have other undesirable knock-on effects. Maybe not in this case, but bodging things to work is not a good habit to get into.yes I have 150 leds but I rigger jigged it so it will work with 151 other wise the last led does not light
Not sure what is going on there, why things are not working with longer pauses. Is your code exactly as was posted and only the PAUSE length changed or have you altered anything else ? If you have it's best to post all your code.when I change the pause to this ... the led strip just stays on with out turning off
okay I was thinking to deep..have to get it simpleIt's really just substitution
#picaxe 20x2
#no_table
#no_data
Symbol PAUSE_WORD = W1
PAUSE_WORD = 20000
; Set how many LED modules in the strip
symbol HOW_MANY_LEDS = 151
; Set the brightness of the LED while testing
; Use small values to keep current consumption low
symbol BRIGHTNESS = 1 ; 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 ) ; 1-64
sendPacket( $FF, $FF, $FF, $FF ) ; 65-128
sendPacket( $FF, $FF, $FF, $FF ) ; 129-192
#endmacro
; Turn a single LED off
#macro ledOff
send( $00, $00, $00 )
#endmacro
; Turn a single LED on
#macro ledOn
send( BRIGHTNESS, $00, $00 )
#endmacro
PowerOnReset:
; Initialise the HSPI interface
init
do
gosub AllOff ; Turn all LEDs off
pause PAUSE_WORD
gosub AllOn ; Turn all LEDs on
pause 2000
loop
AllOff:
head
for w0 = 1 to HOW_MANY_LEDS
ledOff
next
tail
return
AllOn:
head
for w0 = 1 to HOW_MANY_LEDS
ledOn
next
tail
return