Alternating loop
Archiver
Posts: 46,084
Hi all!
I have a need to make my stamp program alternate between two
different sets of code every pass through the program.
I am running two sonar modules and I think they are setting each
other off because they are pinging one right after the other. If I
could make the program alternate it would ping one then the next time
through the program it would ping the other.
TIA
Doug
I have a need to make my stamp program alternate between two
different sets of code every pass through the program.
I am running two sonar modules and I think they are setting each
other off because they are pinging one right after the other. If I
could make the program alternate it would ping one then the next time
through the program it would ping the other.
TIA
Doug
Comments
You can do that with a State Machine. i.e.,
laststate var bit
laststate=0
Main:
if laststate =1 then Check_sonar2
Check_sonar1:
"get data from Sonar1"
Laststate=1
goto main
Check_sonar2:
"get data from sonar2"
laststate=0
goto main
I'm sure there is a more elegant solution but this might work.
Jeff
other on the next pass? Just use a bit variable -- when it is true, fire one
module, false, fire the other. Just toggle the value each pass.
Original Message
> I have a need to make my stamp program alternate between two
> different sets of code every pass through the program.
>
> I am running two sonar modules and I think they are setting each
> other off because they are pinging one right after the other. If I
> could make the program alternate it would ping one then the next time
> through the program it would ping the other.