Any explanation for weird memory behavior?
StephenMoore
Posts: 188
Why doesn't this code rotate the array? It loads up the array with the last value only. That is it it fails to copy the first element. Any ideas anyoune?
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 _RED = $FF0000 '' Offer up some basic color schemes _GREEN = $00FF00 _BLUE = $0000FF _PINK = $FF0F0F _LTGRN = $0FFF0F _LTBLU = $0F0FFF _YELLO = $FFFF00 _MAGEN = $FF00FF _CYAN = $00FFFF NUMLED = 50 NUMLETTER = 5 LEDPERLETTER = NUMLED/NUMLETTER OBJ pst : "Parallax Serial Terminal" VAR long RGB[NUMLED] long colorArray[NUMLETTER + 1] PUB LED pst.start(115200) setColorArray rotateColorArray PRI rotateColorArray | idx long[@colorArray][NUMLETTER] := long[@colorArray][0] '' set last value in array = to first value pst.hex(long[@colorArray][NUMLETTER], 6) pst.char($0D) repeat idx from 1 to (NUMLETTER ) '' rotate values down long[@colorArray][idx-1] := long[@colorArray][idx] PRI setColorArray long[@colorArray][0] := _PINK long[@colorArray][1] := _YELLO long[@colorArray][2] := _LTGRN long[@colorArray][3] := _BLUE long[@colorArray][4] := _RED pst.hex(long[@colorArray][0], 6) pst.char($0D)
Comments
IOW, the rotation function is perfectly fine.
-Phil
Edit: I see Phil bet me to it.
D'oh!
-Phil
I have a string of 50 RGB leds grouped into letters of 10 leds each. When I use the rotateColorArray routine it all turns red. Here is the complete listing. It is really baffling to me because it should be working.
I don't know if that's the only problem, but it should help.
I really appreciate you guys who help out. You have talent and share it willingly: a great and rare commodity these days.
Why did that work? The dimension of colorArray is NUMLETTER + 1, so the last element is colorArray[NUMLETTER].
-Phil
I didn't notice the size was "+1".
But since only 4 elements had been shifted (from 1 through 4 to 0 through 3), then element #4 is the one I thought was supposed to receive the value from (the previous) element #0.
-Phil
You may have been thinking about strings, which are byte arrays whose size needs to be one greater than the number of actual characters, in order to accommodate the zero termination byte.
-Phil
I need a strategy for fadeLED(@RGB, @RGB2).
It is not clear to me what the most aesthetic traverse of color space would be. Here is my attempt at it but it washes out color.