Shop OBEX P1 Docs P2 Docs Learn Events
how to hold the line until button is press — Parallax Forums

how to hold the line until button is press

jonykkjonykk Posts: 17
edited 2012-05-22 20:35 in BASIC Stamp
Hi there,

Im using BS2pe. What i want is the program will loop on the main program, when "enter" is pressed, it will compare the AD and the refvoltage. It will either give a pass or fail. Then it will wait for another time for button press only the program will continue. Im having a problem on the button part. The problem is my program will stuck at "Pass!! Enter to continue". And i have to press few times on the button only the program will back to the subprogram i want.

Here is my code. Thank you.

Main:
IF (IN11 = 1) THEN
IF (AD < refVoltage + (tolNumber/100) OR AD > refVoltage - (tolNumber/100)) THEN ' this line will compare the data.
HIGH LEDGreen
SEROUT RX,BAUD, ["Pass!! Enter to", CR, "continue."]
'PAUSE 10
DO WHILE IN11=0:
'IF (IN11 = 1) THEN
LOW LEDGREEN
GOTO main
'ENDIF
LOOP

ELSE
HIGH LEDRED
SEROUT RX,BAUD, ["FAIL!! Enter to", CR, "continue."]
'PAUSE 10
'DO
'IF (IN11 = 1) THEN
LOW LEDRED
GOTO main
'ENDIF
'LOOP

ENDIF
ELSE
oddSign = 1
GOSUB convert
GOSUB calc_volts
GOSUB display
PAUSE 500
GOTO main
ENDIF

Comments

  • ercoerco Posts: 20,256
    edited 2012-05-21 22:14
    Did you define variables AD, refVoltage & tolNumber ? Where are their values coming from, an ADC? Throw in a few DEBUG statements so you can see their values and determine if your math and intentions are right.
  • jonykkjonykk Posts: 17
    edited 2012-05-21 23:55
    Hi,

    All the variables are declared and all the compare is ok....My problem is the button part....when the LCD display out "Pass....." i hold the program until i press the enter again...only it will run...but i need to press a lot of times only the program will loop back to the main......u get what i mean??
  • ercoerco Posts: 20,256
    edited 2012-05-22 01:38
    Yep, you need to do to multiple button checks each time and be aware when a button needs to be pressed and when it needs to be released. I won't rob you of the joy of discovery, but consider this method, which waits for a button press & release:

    Main:
    If in11=0 then main ' loop back if button not pressed
    Hold:if in11 =1 then hold ' stay here until button released
    etc...
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2012-05-22 07:59
    Part of the difficulty for us to offer useful help is that it is hard to follow the logic of your code as posted. I reformatted it below with indentation and also tags that keep the indentation intact for display here. The way I understand it, you want to prepare the test and then press the button and it will come up with "pass" or "fail", and then you set up a new test and press the button again when ready, and so on. Is that right?

    attachment.php?attachmentid=78421&d=1297987572
    ' {$STAMP BS2pe}
    ' {$PBASIC 2.5}
    Main:
      IF (IN11 = 1) THEN
        IF (AD < refVoltage + (tolNumber/100) OR AD > refVoltage - (tolNumber/100)) THEN ' this line will compare the data.
          HIGH LEDGreen
          SEROUT RX,BAUD, ["Pass!! Enter to", CR, "continue."]
          'PAUSE 10
          DO WHILE IN11=0:
            'IF (IN11 = 1) THEN
              LOW LEDGREEN
              GOTO main
            'ENDIF
          LOOP
    
        ELSE
          HIGH LEDRED
          SEROUT RX,BAUD, ["FAIL!! Enter to", CR, "continue."]
          'PAUSE 10
          'DO
            'IF (IN11 = 1) THEN
              LOW LEDRED
              GOTO main
            'ENDIF
          'LOOP
    
        ENDIF
      ELSE
        oddSign = 1 
        GOSUB convert 
        GOSUB calc_volts
        GOSUB display
        PAUSE 500 
        GOTO main
      ENDIF
    
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2012-05-22 08:06
    The logic of the program is convoluted. Maybe you are looking for something more straightforward along these lines. One press of the button=one test.
    MAIN2:
      DO
        SEROUT RX,BAUD, ["Enter to", CR, "run test."]
        DO : LOOP UNTIL IN11   ' wait for button up
        DO : LOOP WHILE IN11    ' wait for button down
        GOSUB  convert       ' do test and display
        GOSUB  calc
        GOSUB  display    ' and show pass or fail
      LOOP
    
  • ercoerco Posts: 20,256
    edited 2012-05-22 13:59
    "Convoluted & straightforward". Masterfully and thoughtfully worded. As ever, Tracy, you are a gentleman and a scholar, in addition to being a delightfully helpful fellow.
  • jonykkjonykk Posts: 17
    edited 2012-05-22 20:35
    Hi everyone,

    Thank you all for the reply and the comment given.... I had found the solution..Here is my new code and it works charmingly..i separate all the IF condition into subroutine.....anyone do not understand me please reply here... i will try my best to explain...thank you!!!!
    main:
    IF (enter is press) then
    GOSUB check
    ELSE
    GOTO main:
    
    check:
    IF (condition) then
    Display "Pass"
    GOSUB waitbutton
    ELSE
    Display "Fail"
    GOSUB waitbutton
    ENDIF
    
    
    waitbutton:
    DO
    IF(enter is press) then
    EXIT
    ENDIF
    LOOP
     RETURN
    
Sign In or Register to comment.