Help with counting inputs
Kenny D
Posts: 8
Hi everyone,
I have just started playing around with Boe Bot. It's great fun.
Can someone help me with this?·
I am trying to get Boe Bot to follow a course using a microswitch tied to input 7.· The microswitch feels for these
poles I have set up.·I want to be able to set a constant and have the Bot move forward until input 7· counts up to the constant
and then stop.·
·I would then like it to reset the counter and move backwards until it counts to another constant.
·I have tried many different things·that resemble··
IF (IN7 = 0) THEN
··· counter = counter + 1
····· IF (counter =7) THEN
·GOSUB forward
······ I know I am far off..so please help
Thanks in advance.
·
Kenny
I have just started playing around with Boe Bot. It's great fun.
Can someone help me with this?·
I am trying to get Boe Bot to follow a course using a microswitch tied to input 7.· The microswitch feels for these
poles I have set up.·I want to be able to set a constant and have the Bot move forward until input 7· counts up to the constant
and then stop.·
·I would then like it to reset the counter and move backwards until it counts to another constant.
·I have tried many different things·that resemble··
IF (IN7 = 0) THEN
··· counter = counter + 1
····· IF (counter =7) THEN
·GOSUB forward
······ I know I am far off..so please help
Thanks in advance.
·
Kenny
Comments
counter = counter + 1
IF (counter < 7) THEN
GOSUB forward
this should work. (notice the less than)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Note that ^ is the Stampese XOR and & is Stampese AND, bitwise, so the thing in () is 1 only when in7 makes the transition from 0 to 1, and that gets added directly to the counter.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
I am trying to get a generic working program so I can modify it as needed later.
Right now I am just messing with one wheel until I have it down. I am having a problem with the second movement.
The wheel will not pulse like the first time.
Forward1 works fine. When it gets to back1 the wheel moves slow and jerky ant not at the speed I told it to.
I have tried several speeds with no change.
Any suggestions??
thanks
[noparse][[/noparse]Variables]
newin7 VAR Bit
oldin7 VAR Bit
oldin7 = IN7
counter VAR Byte
'
[noparse][[/noparse] Main Routine ]
DO
newin7 = IN7
counter = counter + (newin7 ^ oldin7 & newin7) ' increment on 0-->1 transition
oldin7=newin7
DEBUG ? counter
IF (counter > 7) THEN
GOSUB forward1
PAUSE 10
IF (counter > 9) THEN
GOSUB back1
PAUSE 10
ENDIF
ENDIF
LOOP
forward1:
PULSOUT 13, 850
RETURN
back1:
PULSOUT 13, 650
RETURN
IF (counter > 7) THEN
GOSUB forward1
PAUSE 10
IF (counter > 9) THEN
GOSUB back1
PAUSE 10
ENDIF
ENDIF
Once counter is greater than 9, you're calling both the forward1 and back1 subroutines. I'm not sure exactly what you're trying to do, but this code:
will do nothing until counter is greater than 7. It will call forward1 when counter is 8 & 9. Once counter is greater than 9, it will call back1.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
Then,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
The following code does what I need it to do.··I although I couldn't· get the MODE variable to work.
·My programming knowledge is still a beginner.
I would like to get an output to work when the pogram hits each goal.· However,
··the program has the·output·as part of the loop, so the output doesn't work·correctly.
Any suggestions as how to make the output work outside the loop?
Thank you sooo much for your help...
Kenny
Please go back and re-read the message you posted, as it doesn't make a whole lot of sense, in a number of places. Here's what I mean:
First you say "... I couldn't get the MODE variable to work." yet there is NO "MODE" variable in the program. What's the story with that?
You also say "The following code does what I need it to do." but later on say "... the output doesn't work correctly." Does it work, or doesn't it work, and if it doesn't work, what is the program doing differently from what you want it to do?
Then, in the program, the following code seems rather odd:
ELSEIF (counter >= 16 ) AND (counter <=33) THEN
GOSUB back
ELSEIF (counter >= 16 ) AND (counter <=33) THEN
GOSUB forward
Last, just as a suggestion, you may find that using SELECT ... CASE is a bit easier to use and understand than all of those IF ... THEN statements. SELECT ... CASE works very well for range values.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->