cylon flashing light code in spin doesn't seem to work the way its supposed to
I wrote this code to flash LEDs (pins) 9 8 7 6 5 4 back and forth
however the code below only flashes the lights in the follwing sequence:
9 8 7 6 5 6 7 8 9 8 7 6 5 6 7 8 9 etc
it doesent light up LED 4, how come?
The problem seems to be on line 7 below which states:
if outa[9..4] ==%000001
This line should get triggered when LED 4 is light and thus go into a loop which reverses the flashing lights. INstead the code only works the way it supposed to when i change the above line to:
if outa[9..4] ==0
I can't figure out why. Any help would be much appreciated.
PUB ShiftLedsLeftRight ' Method declation
dira[9..4]~~
outa[9..4] :=%100000
repeat
waitcnt (clkfreq/5 + cnt)
outa[9..4] >>=1
if outa[9..4] ==%000001 "line 7
repeat until outa[9..4] ==%100000
if outa[9..4]==0
outa[9..4]:=%000001
outa[9..4] <<=1
waitcnt (clkfreq/5 + cnt)
however the code below only flashes the lights in the follwing sequence:
9 8 7 6 5 6 7 8 9 8 7 6 5 6 7 8 9 etc
it doesent light up LED 4, how come?
The problem seems to be on line 7 below which states:
if outa[9..4] ==%000001
This line should get triggered when LED 4 is light and thus go into a loop which reverses the flashing lights. INstead the code only works the way it supposed to when i change the above line to:
if outa[9..4] ==0
I can't figure out why. Any help would be much appreciated.
PUB ShiftLedsLeftRight ' Method declation
dira[9..4]~~
outa[9..4] :=%100000
repeat
waitcnt (clkfreq/5 + cnt)
outa[9..4] >>=1
if outa[9..4] ==%000001 "line 7
repeat until outa[9..4] ==%100000
if outa[9..4]==0
outa[9..4]:=%000001
outa[9..4] <<=1
waitcnt (clkfreq/5 + cnt)

Comments
You can either use the post code button "#" (after clicking "go advanced") or insert code tags yourself.
[C0DE]
your code goes here
[\C0DE]
I used a zero instead of an "O" in code so you could see the tags. You'd want to use an "O" in the word code.
My guess is you're shifting the bit from pin 4 before there's a waitcnt. Try swapping the last two lines.
Duane
PUB ShiftLedsLeftRight ' Method declation dira[9..4]~~ outa[9..4] :=%100000 repeat waitcnt (clkfreq/5 + cnt) outa[9..4] >>=1 if outa[9..4] ==%000001 repeat until outa[9..4] ==%100000 if outa[9..4]==0 outa[9..4]:=%000001 waitcnt (clkfreq/5 + cnt) outa[9..4] <<=1pri cylon_eyes(msb, lsb, delay) '' Runs Glenn Larson "cyclon eyes" style in own cog dira[msb..lsb]~~ outa[msb..lsb]~ outa[msb] := 1 repeat repeat until outa[lsb] waitcnt(cnt + delay) outa[msb..lsb] >>= 1 repeat until outa[msb] waitcnt(cnt + delay) outa[msb..lsb] <<= 1I'm guessing -- based on purpose and your code -- that you are launching this method into its own cog. I tested on the Propeller Demo Board with this call: