Button Questions
ckung
Posts: 6
Hmm... currently i am working on my project which need programming using BS. I face one stupid problem which make my life . The problem is·listed below:
my project needed user to press one button which will then access other coding. But my problem is like this, we i pressed the button, the BS will run the coding,but after i released it, it will stop at the half way. If i wished the BS to finish the rest of the coding, i need to make sure that the button signal is always high.
Hope u guys understand wat i try to say here, my eng sux.....
Conclude, wat i wan is when·i press and release a button(within 1 sec), i hope tat the BS will work for the rest of the programming code(for example 10 sec).
Thanks for sharing ur info
Post Edited By Moderator (Chris Savage (Parallax)) : 5/10/2007 2:31:36 PM GMT
my project needed user to press one button which will then access other coding. But my problem is like this, we i pressed the button, the BS will run the coding,but after i released it, it will stop at the half way. If i wished the BS to finish the rest of the coding, i need to make sure that the button signal is always high.
Hope u guys understand wat i try to say here, my eng sux.....
Conclude, wat i wan is when·i press and release a button(within 1 sec), i hope tat the BS will work for the rest of the programming code(for example 10 sec).
Thanks for sharing ur info
Post Edited By Moderator (Chris Savage (Parallax)) : 5/10/2007 2:31:36 PM GMT
Comments
Normally, when using a button to activate some routine, you have a loop that checks for a button press, then checks for a release like:
Alternatively, you can reverse these and wait first for the button to be released:
····GOSUB wait1········· ' estimate 2 sec
··· GOSUB wait2········· ' estimate 3 sex
_____________________________________________________________________
My coding is similar like above:
·· When i pressed the button and released after 2 sec, i found that the BS did not go to sub routine (wait2),
if i wish to do so, i need to press the button for 5 sec for the bs to run all the programming code.
·· What i wan here is i hope that the bs will run the entire code when i press for only 2 sec or less.
Thanks for ur info and reply....
sample VAR Word
counting VAR Word
LOW btn1
LOW btn2
main:
IF (btn1>0)THEN
··· GOSUB Motor1
··· GOSUB Motor2
ELSE
··· DEBUG "Please Press the Button"
··· GOTO main
ENDIF
··· GOTO main
Motor1:
FOR sample = 1 TO 10
· PULSOUT 0,1900
· PAUSE 50
· NEXT
RETURN
Motor2:
FOR sample = 1 TO 10
· PULSOUT 1,2800
· PAUSE 50
NEXT
RETURN
__________________________________________________________
hope u understand
2) When btn1 becomes a logic high, Motor1 and Motor2 are executed. Motor1 takes about 1/2 second to execute and Motor2 takes slightly more to execute. During that time, the Stamp can't do anything else. The button isn't checked again until afterwards.
You might put a test for the release of btn1 after the 2nd GOSUB like:
What i found out from the coding is tat when i release the button, the program stop and didnt continue it progress till the end.(for ex:Maybe stop b4 subroutine Motor2 is called.)
what i wish is tat i hope i can make the stamp to execute subroutine of Motor1 and motor2 (For ex: last for 5 sec) while i online pressed the button for 2 sec.
What i get from the coding is tat if i pressed the button for 2 sec, the programming will only run for 2 sec instead of the whole coding under the IF (Btn = 1) statement.
It's possible that the Stamp is resetting during the Motor1 routine for some reason. I don't know what your circuit is or what the PULSOUT is doing, but I suspect you're trying to control some kind of servo motor. It's possible that the drain of the motor is causing the power supply voltage to drop below the threshold where the Stamp will reset. If you put a DEBUG "Initialization started" statement at the beginning of your program (before main[noparse]:)[/noparse], you may see that this is happening.
In the future, please post a schematic of your system as well as the source of your program. It would save a lot of guessing.
After some testing and checking, i found that (maybe) like as u said, the motor drew all the power which cause the stamp start from the very begining again(start before main).
any suggection on how to overcome this problem?
I am now using a 500mA 6v adapter to connect my basic stamp,lets say if i try to use a 1A or more 6V power supply(any limitation for ampere?), can thise solve my problem?
Thanks for ur info......
P/S: Not i don wan post my schematicbut is tat i don really doing it, just briefly test on wat i am going to do...
I will try it out. Have a nice day