Shop OBEX P1 Docs P2 Docs Learn Events
Button Questions — Parallax Forums

Button Questions

ckungckung Posts: 6
edited 2007-05-10 16:58 in Learn with BlocklyProp
Hmm... currently i am working on my project which need programming using BS. I face one stupid problem which make my life confused.gif . 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.....eyes.gif
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 yeah.gifyeah.gifyeah.gif

Post Edited By Moderator (Chris Savage (Parallax)) : 5/10/2007 2:31:36 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-10 14:04
    I'm not sure what you are describing. Please post your program as an attachment.

    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:
    Wait1:
    If IN0 = 1 then Wait1 ' Wait for a low input (button pressed)
    Wait2:
    If IN0 = 0 then Wait2 ' Now wait for a high input (button released)
    ' Here's the code to execute on a button press
    


    Alternatively, you can reverse these and wait first for the button to be released:
    Wait1:
    If IN0 = 0 then Wait1 ' Wait for a high input (button released)
    Wait2:
    If IN0 = 1 then Wait2 ' Now wait for a new press (low input)
    
    
  • ckungckung Posts: 6
    edited 2007-05-10 14:20
    IF (button>0)THEN

    ····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....
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-10 14:25
    I can't help you unless you post all the code or at least all the referenced declarations (VAR/CON/PIN) and all the routines that are called (like wait1, wait2 and what they might call).
  • ckungckung Posts: 6
    edited 2007-05-10 14:35
    btn1 PIN 3

    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
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-10 14:53
    1) I don't understand why you have a "LOW btn1" in your initialization. In the rest of your code, you're using btn1 as an input.

    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:
    GOSUB Motor2
    DO
    LOOP UNTIL btn1 = 0
    
  • ckungckung Posts: 6
    edited 2007-05-10 15:08
    the initialization is done to make sure the Btn go LOW when the programming start and it didnt effect much.

    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.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-10 15:20
    I don't know how you have connected the button, but, if it connects the I/O pin to +5V and the button happens to be pushed when the LOW btn1 is executed, you can destroy the I/O pin with the resulting short circuit. I suggest you remove the LOW and use "INPUT btn1" instead.

    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.
  • ckungckung Posts: 6
    edited 2007-05-10 16:33
    Thanks for ur suggestiong.

    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...
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-10 16:54
    Use two separate power supplies, one for the motors and the other for everything else. You have to have a common ground connection. Sometimes using a large electrolytic capacitor across the power supply will help (maybe 2200uF 10V or two 1000uF 10V in parallel). Sometimes isolating the motor(s) with a small inductor (1uH low resistance), then a large capacitor across the motor terminals will help. Often the problem is due to an instantaneous high drain that this filtering can fix. Ordinary servo motors can draw more than 1A sometimes for a short period of time, particularly when under high mechanical load.
  • ckungckung Posts: 6
    edited 2007-05-10 16:58
    thanks a lot man, u help me a lot. Even my prof lec also confusing me with unrelated info(i guess).smilewinkgrin.gif

    I will try it out. Have a nice day
Sign In or Register to comment.