Would it be the IF...ELSEIF Command or something else???
gr8_big_geek
Posts: 34
Okay, I'm trying to run a proceedure until a button is pressed. If the button is not pressed then run the proceedure to the end of its cycle.
I'm having the hardest time getting this right. I've got all of my other coding to run my robot, all but this.
I'm trying to use the the if, elseif, goto commands, and I'm so turned around I don't know which way is up. I am using Basic Stamp v2.4 on windows XP SP2 (not sure if that matters, but I'll just throw it in there).
I have attached the file of the coding I'm working on right now. If you have some time, please look it over and shed some light on my blank spot. I usually am good at working these codes out, but I think I've just been looking at it too long.
Thank you...and I mean that!!! THANK YOU in advance, It really means a lot to me (I'm at the end of my rope)
Your Geek~
I'm having the hardest time getting this right. I've got all of my other coding to run my robot, all but this.
I'm trying to use the the if, elseif, goto commands, and I'm so turned around I don't know which way is up. I am using Basic Stamp v2.4 on windows XP SP2 (not sure if that matters, but I'll just throw it in there).
I have attached the file of the coding I'm working on right now. If you have some time, please look it over and shed some light on my blank spot. I usually am good at working these codes out, but I think I've just been looking at it too long.
Thank you...and I mean that!!! THANK YOU in advance, It really means a lot to me (I'm at the end of my rope)
Your Geek~
Comments
two things:
1. Indent your code so it's easier to see where the blocks are.
2. Make sure your button/switch is debounced.
Once you indent, you might see if you've made logical errors (I didn't look that close, but jumps and labels nested inside IFs and DO's can get messy.)
HTH
- Howard
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
2. Your labels GOTO are not "ended" properly - I would use subroutine instead just to return to your main if...else safely.
·· (But you would have to redo the main loop.)
·· Executing at label time_me8:··"falls thru " to yur next label even with improperly placed ENDIF
3.·It is not necessary to test ELSEIF in = 0 since you have only two values 0 and 1 posible anyway.
····simple
··· IF IN = 1 then do this ....
·· ELSE
····· do this...
···ENDIF
·And as already·said - indent and you will be happier coder.
Partialy edited code attached
Cheers Vaclav
PS To debounce is to eliminate mechnical devices ea pushbuttons in particaular to send multiple electrical pulses when single pulse is expected.
···· Check BUTTON command.
Post Edited (vaclav_sal) : 7/14/2009 6:32:24 PM GMT
It sounds like I'm needing some "step out" command that will allow my program to step outside of the loop, or nested looping. I thought that's what GOTO was used for, but maybe I'm using it incorrectly.
I'm basically wanting to tell the code to run so long as the button is NOT pressed, once the button IS pressed terminated your action (of pressing your little robot arm forward), provide the time it took you to reach the "button press", and also STOP pushing forward!
If you could help me figure that out, that would be awesome!!! I'm very willing to practice with some alternantive coding ideas, I'm just completely out of ideas on it. I've worked on my coding now for about a month. I have gotten all of the other aspects of the coding worked out great, but this one has got me beat.
I just got your edited version of the code. I will try that out and see if that works. My biggest concern was getting the code to know (at any point in time durying the running) whether the button was pressed, and at THAT moment go to option 2.
For some reason it doesn't see when I press the button. If I start out in the beginning pressing the button, then it will go to option 2 but otherwise it does not seem to know/see when I'm pressing the button.
Either way, I'll try your version and repost. Thank you for all of your time in helping me [noparse]:)[/noparse]
Matt, eh-hem, gr8_big_geek~
> If I start out in the beginning pressing the button, then it will go to option 2
Sounds like a bouncy switch. You see, when you press a mechanical switch, it actually doesn't close (or open) instantly at once. If you look at the connection with a fast enough detection device, you'll see that it is really turning on and off many times before it closes. That's why if you start off with the button pressed, it will have enough time to fully close *before* your code runs - so it get's it right (assuming there's no other logic errors in the code). Even if your code is right, this will cause problems, so you have to make sure it's properly debounce.
Here's The Manual on switch bounce:
http://www.ganssle.com/debouncing.pdf
And if you do a forum search on 'debounce' you'll probably find more info. (Don't use the search button on the top right of this page - it's bjorked up - use: search.parallax.com)
http://search.parallax.com/search?q=debounce
> Thank you for all of your time in helping me [noparse]:)[/noparse]
Hey, no problem - that's why we're here - and because we also all need assistance too [noparse]:)[/noparse]
- Howard
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Post Edited (CounterRotatingProps) : 7/14/2009 9:29:05 PM GMT
'OPTION 1, IF BUTTON IS NOT PRESSED (or if it is at its usual position)
'then continue to "time_me8"
LooK:
IF IN3 = 1 THEN
GOTO time_me8
'If it is not at its usual place then stop the program with "time_stopper".
ELSEIF (IN3 = 0) THEN
GOTO time_stopper
RETURN
I hope this helps let me know if this works for you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
It needs to stop (even if it happens to be half way through) when the button is pressed. If it doesn't it will knock all of my blocks over.
Sam- I tried your code and the arm extended and stayed that way, even if/when I pressed the button. It just continued to repeat over and over again with the arm outwardly pressed.
Still working on the coding for this. I did take a few things and put them into the attached, it still is not working completely yet. I'll keep on it though.
I'll keep reading more about the bouncy bouncy stuff and see what I can make of it though
I attached the completed copy to this so you can see. I think I've just been really tired and frustrated so I couldn't focus on it. I thought about it all night at work, then it hit me. I came straight home and worked in the code I had thought about and poof!
It was my DO...LOOP, I was working it incorrectly.
Thank you for all of your help, you all are so smart and it's wonderful to be able to chat with you!
Matt~ AKA gr8_big_geek
If I was your "computer science"·teacher·you would get C-!
Your IF· commands are still not correct.
As stated before you need proper syntax
··· IF··
··· do something
·· ELSE
·· do something···
·· ENDIF
Maybe what is missing - the processor does something when IF is true and than skips over the ELSE to the end of the IF command.
It works in your case but you have a simple two way decisison to deal with.
Cheers Vaclav
·
The way you are describing does not work for the functionality of this project because with using the standard format of IF..ELSE...ENDIF; as with your suggestions the button needs to be pressed at the time of the beginning of the code in order for the IF....(do something)...ELSE...(do something)...ENDIF to recognize option 2.
The problem lies in looping back to the beginning and continuing that loop so that the code continues to check whether the button is pressed at any point. The loops are short enough that it checks quickly and there isn't a delay in the pressing of the button.
It has never been about a fork in the road where the code needed to follow one route or another; it has been about continuing in one operation unless interrupted, or otherwise told to stop by a button press.
In this example or coding the time counts, the operation continues down path A unless a button press interrupts its cycle, then it goes down path B, which is to provide the time it took and then END.
I understand the function of the IF..ELSE..ENDIF...functions. However, I also understand my project.
I'm working on a complex robotic device that has an airdraulic arm that is now functioning correctly thanks to the code I have attached above. It's a darn good thing you aren't my science teacher because you would be grading out of ignorance as apposed to logic.