Counting problem
Hi guys,
I've seen it, but I can't find it now that I need it.
I want to run a counter from 40 to 100 at 20 step intervals and back down and repeat (i.e. 40 60 80 100 80 60 40 60 80 100... and so on). I can't remember the formula for it. I know it was an easy one as well. Can anyone help please.
Thanks,
Tony
I've seen it, but I can't find it now that I need it.
I want to run a counter from 40 to 100 at 20 step intervals and back down and repeat (i.e. 40 60 80 100 80 60 40 60 80 100... and so on). I can't remember the formula for it. I know it was an easy one as well. Can anyone help please.
Thanks,
Tony

Comments
' {$STAMP BS2} ' {$PBASIC 2.5} counter VAR byte FOR counter = 40 TO 100 STEP 20 DEBUG DEC counter, cr next FOR counter = 100 TO 40 STEP 20 DEBUG DEC counter, CR nextThat should work.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
·· Other than the DO...LOOP to cycle the whole thing over it is exactly what you asked for.· Without more details that's the best I can offer.· Your new details somewhat contradict the original post.· You mentioned increments of 20, but now you're mentioning increments of 1.· The DEBUG statements were there simply for filler, you could easily assign that counter to a delay or whatever.· Perhaps you should list exactly what you need to do.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
' {$STAMP BS2} ' {$PBASIC 2.5} counter VAR Byte offset VAR Byte counter = 40 offset = 20 DO DEBUG DEC counter, CR PAUSE 500 counter = counter + offset IF counter = 40 OR counter = 100 THEN offset = -offset ENDIF LOOPThis one may be closer to what you wanted.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
' {$STAMP BS2} ' {$PBASIC 2.5} idx VAR NIB value VAR BYTE DO LOOKUP idx, [noparse][[/noparse]40, 60, 80, 100, 80, 60], value DEBUG "Do stuff here" idx = idx + 1 // 6 ' Change 6 to the number of values in your list LOOP▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
'{$STAMP BS2}
reps VAR Nib
rate VAR Byte
x VAR Byte
rate = 100
variablespeed:
FOR x = 0 TO 5
FOR reps = 1 TO 2
HIGH 1
PAUSE rate
LOW 1
PAUSE rate
NEXT
FOR reps = 1 TO 2
HIGH 2
PAUSE rate
LOW 2
PAUSE rate
NEXT
PAUSE 2000
LOOKUP x, [noparse][[/noparse]80, 60, 40, 60, 80, 100], rate
NEXT
GOTO variablespeed
Thanks for the input guys, I really appreciated it.
You should see the values cycle through the values in the list.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows