!!!!! The Hardest Thing I've ever had to program !!!!!!!!!!!!!!
gr8_big_geek
Posts: 34
Greetings all!
I have a push button on the end of a rod. I have my servo set to·slide this rod forward UNLESS something is obstructing the way of the rod, in which case I want the servo·sliding the rod forward to STOP IMMEDIATELY!
To slide the rod forward I am using the following:
This code works perfectly in sliding the rod forward, only it extends the rod completely forward regardless of obstructions.
****Here is where it gets tricky. I am trying to start a timecounter when the rod is told to slide forward, IF the button is pressed, I need the timecounter to STOP counting (at the same time the servo STOPS pushing the rod). I basically need to know how long this rod is being extended before it·becomes obstructed so I need the time to return, maybe in a debug mask? <---I'm not sure...
I am completely at my wits end. I have tried using nested loops and such but I am terrible at them. All of my variations have not worked. I have also played with that timecounter = timecounter yadda, yadda, yadda thing, but it has not worked well for me.
If you all have any suggestions please let me know.
Just as an FYI: I have two different buttons I can try. One clicks in when you press it, and it stays in until you press it again. Then I have another type of button that does not click in, it just presses, makes contact, and then bounces, or springs back to the same position. Should I use one over the other?
Completely lost,
gr8_big_geek
I have a push button on the end of a rod. I have my servo set to·slide this rod forward UNLESS something is obstructing the way of the rod, in which case I want the servo·sliding the rod forward to STOP IMMEDIATELY!
To slide the rod forward I am using the following:
' {$STAMP BS2} ' {$PBASIC 2.5} counter VAR Word '**************************(Slide Rod Forward)****************************** FOR counter = 1 TO 40 PULSOUT 4, 1000 PAUSE 22 NEXT PAUSE 2000
This code works perfectly in sliding the rod forward, only it extends the rod completely forward regardless of obstructions.
****Here is where it gets tricky. I am trying to start a timecounter when the rod is told to slide forward, IF the button is pressed, I need the timecounter to STOP counting (at the same time the servo STOPS pushing the rod). I basically need to know how long this rod is being extended before it·becomes obstructed so I need the time to return, maybe in a debug mask? <---I'm not sure...
I am completely at my wits end. I have tried using nested loops and such but I am terrible at them. All of my variations have not worked. I have also played with that timecounter = timecounter yadda, yadda, yadda thing, but it has not worked well for me.
If you all have any suggestions please let me know.
Just as an FYI: I have two different buttons I can try. One clicks in when you press it, and it stays in until you press it again. Then I have another type of button that does not click in, it just presses, makes contact, and then bounces, or springs back to the same position. Should I use one over the other?
Completely lost,
gr8_big_geek
Comments
When your limit switch is activated, just GOTO out of the loop and the loop counter will give you a time in units of 24ms.
Thank you so much for your reply and everything you are doing to help me; it really means a lot as I have really no friends I can talk to about this problem! [noparse]:)[/noparse]
Matt, eh-hem, gr8_big_geek
www.parallax.com/StoreSearchResults/tabid/768/List/0/SortField/4/ProductID/139/Default.aspx?txtSearch=whats+a+microcontroller
www.parallax.com/StoreSearchResults/tabid/768/List/0/SortField/4/ProductID/143/Default.aspx?txtSearch=stamp+basic+syntax
' {$STAMP BS2}
' {$PBASIC 2.5}
counter VAR Word
timecounter VAR Word
'**************************(Push Rod Forward)******************************
FOR counter = 1 TO 40
PULSOUT 4, 1000
PAUSE 24
NEXT
'**************************(Start The Clock)*****************************
DEBUG "Waiting until button is pressed.", CR, CR
DO
LOOP UNTIL IN3 = 0
LOW 1
HIGH 2
timecounter = 0
DO
PAUSE 1
timecounter = timecounter + 1
LOOP UNTIL IN3 = 1
LOW 14
DEBUG "Your time was ", DEC timecounter,
" ms.", CR, CR
I just don't know how to fuse both of these together. The rod pushes forward, THEN my timer starts goes all the way to the end, and then the timer sequence begins. I don't know how to start the timer and the rod pushing with the exception that if the button is clicked then the whole thing stops and returns the total time activated.
SRLM I see your code you put in there, but where do I type "main: IF" and such? Or where would I work it in my code?
before your FOR and
after the PAUSE 24. Somewhere in your code you have
followed by what you want to do when the button is pushed. "counter" will have the value of the number of times your program has gone through the FOR loop. It's in units of 26ms. As I mentioned, you may need to change the 24 to 18 to keep the servo from jittering from too long a delay between pulses.