It is difficult to tell what you want your program to do. Please explain. If it is a simple running LEDs process where the lights go from one side to another, then back again, your program is not written to do that. The indenting isn't consistent either. Start with a clear description. You probably need an outer loop (REPEAT) and two inner loops, one for going in one direction, the other for going in the other direction.
I've added some comments to your code. File attachments don't seem to work with the Safari browser.
'' File: ShiftRightP9toP4_3.spin
'' ShiftRight and ShiftLeft
'' Demonstrates the right shift and left shift.
PUB ShiftLedsLeft
dira[noparse][[/noparse]4..9]~~
repeat
if outa[noparse][[/noparse]9..4] == 0 ' *** This statement is OK
outa[noparse][[/noparse]9..4] := %100000
waitcnt(clkfreq/1 + cnt) ' Wait = 1 seconde ' *** line this up
outa[noparse][[/noparse]9..4] >>= 1 ' *** Why is this lined up this way?
if outa[noparse][[/noparse]9..4] == %000001 ' *** All of the following only occur when outa is %000001
waitcnt(clkfreq/1 + cnt) ' *** and that's probably not what you want
outa[noparse][[/noparse]9..4] := %000010
waitcnt(clkfreq/1 + cnt)
outa[noparse][[/noparse]9..4] <<= 1
Since i'm also a newbee to the propeller, i took it as a challenge to solve Jacks problem. here is my version of the solution.
At least it works. However,i think there is much to improve. May be Mike or someone else can have a look at the code and tell me and Jack, what can be improved.
That's the way , we can learn to understand the propeller
when i first got the proprpm board, it comes with a demo program that was fairly easy to modify to run different patterns. try to load this up and modify as a start...
{{ RunningLEDs.spin }}
CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
PinStart = 0 ' First LED pin (active HIGH)
PinEnd = 7 ' Last LED pin (active HIGH)
Pins = || (PinStart - PinEnd) ' Doesn't matter if PinStart < PinEnd
Delay = 250 ' Delay in milliseconds
PUB MainProgram | i
dira[noparse][[/noparse]PinStart..PinEnd]~~ ' Make outputs
outa[noparse][[/noparse]PinStart..PinEnd]~ ' Initially off
repeat
outa[noparse][[/noparse]PinStart..PinEnd] := 1 ' Start with LSB
repeat Pins - 1 ' Repeat for each other bit
waitcnt((clkfreq/1000)*Delay + cnt)
outa[noparse][[/noparse]PinStart..PinEnd] <<= 1 ' Move to next higher bit
repeat Pins - 1
waitcnt((clkfreq/1000)*Delay + cnt)
outa[noparse][[/noparse]PinStart..PinEnd] >>= 1 ' Move to next lower bit
waitcnt((clkfreq/1000)*Delay + cnt) ' Delay for last bit to show
Mike,
yes, you solved it much more elegantly. you only have to set PinStart and PinEnd and everything else needed to run the program is calulated automatically.
Thats the way i wanted it too, but do to lack of enough experience with SPIN, i didnt came up with a good solution.
I'm a C programmer and still have to get more aquainted to SPIN, which has a c-like(or at least similar) syntax, but there are differences.
propelleruser999 said...
I'm a C programmer and still have to get more aquainted to SPIN, which has a c-like(or at least similar) syntax, but there are differences.
Like many of us [noparse]:)[/noparse]· I'm not a LISP programmer, but it looks like the "repeat while ..." construct comes from LISP.
I thought that Nightrider special effect was cool ... gives a searching feeling. It has been on·some·movie-bots too.
Jack, Not that it matters, but you only need to use dira[noparse][[/noparse]5..0]~~ once in your program.
that fits your special 6 Led problem for specific pins , that the LEDs are connected. running more LEDs will have you to change all of your code.
the programs Mike and i have suggested , use variables in the VAR sections and
some code changes in your program.
with Mike's version:
once you decide to put your LED's on other pins ,or want to increase or decrease the number of LED's, you simply have to change
StartPin and EndPin in the VAR section and the program runs without changing your whole program again.
Think of a much bigger program ???
You want to change your SD-Card to another pingroup? Just change the start adress (you need no end adress for a SD-card adapter , its already known by your previous program, if programmed that way)
I don't know , if thats the only program you will ever write for the prop; then stay with that.
Comments
I mean the leds wil first shift to the right and then go backwards(shift left) en so on.
(a Nightrider light)
Thanks Mike,
··················· Jack
···· Jack.
I could write the program for you, but you wouldn't learn much from that.
Since i'm also a newbee to the propeller, i took it as a challenge to solve Jacks problem. here is my version of the solution.
At least it works. However,i think there is much to improve. May be Mike or someone else can have a look at the code and tell me and Jack, what can be improved.
That's the way , we can learn to understand the propeller
OUTA[noparse][[/noparse]3..0] := %0101 ' Turns on LED's 0 and 2
OUTA[noparse][[/noparse]0..3] := %0101 ' Turns on LED's 1 and 3
Rather than have two loops, one could simply switch the startPin and EndPin numbers.
I can not find any clou that helps my further. Thanks anyway.
propelleruser999 and hippy thanks for the help.
··············· Jack.
http://elmicro.com/files/manuals/blink10.spin
Thanks you ferry mutch Deiloohay.
············· Jack.
yes, you solved it much more elegantly. you only have to set PinStart and PinEnd and everything else needed to run the program is calulated automatically.
Thats the way i wanted it too, but do to lack of enough experience with SPIN, i didnt came up with a good solution.
I'm a C programmer and still have to get more aquainted to SPIN, which has a c-like(or at least similar) syntax, but there are differences.
learned some new things,thanks.
This is my solution for this program.
Thanks to all.
······ Jack.
I thought that Nightrider special effect was cool ... gives a searching feeling. It has been on·some·movie-bots too.
Jack, Not that it matters, but you only need to use dira[noparse][[/noparse]5..0]~~ once in your program.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
jazzed·... about·living in·http://en.wikipedia.org/wiki/Silicon_Valley
Traffic is slow at times, but Parallax orders·always get here fast 8)
that fits your special 6 Led problem for specific pins , that the LEDs are connected. running more LEDs will have you to change all of your code.
the programs Mike and i have suggested , use variables in the VAR sections and
some code changes in your program.
with Mike's version:
once you decide to put your LED's on other pins ,or want to increase or decrease the number of LED's, you simply have to change
StartPin and EndPin in the VAR section and the program runs without changing your whole program again.
Think of a much bigger program ???
You want to change your SD-Card to another pingroup? Just change the start adress (you need no end adress for a SD-card adapter , its already known by your previous program, if programmed that way)
I don't know , if thats the only program you will ever write for the prop; then stay with that.