How to measure how long I pressed a button ?


Results 1 to 19 of 19

Threaded View

  1. #9
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default Re: How to measure how long I pressed a button ?

    In the initial software, I use a procedure to check the pressed button; if 10 presses have the same ADC as a result, then I validate the button press. I tried to complete the code proposed above with this verification procedure. But, although the results APPEAR to be correct, on the breadboard the assembly does not work at all, none of the 6 commands are executed (of course, I commented Serout instruction and uncomment the other instruction) . Please, could you identify what exactly I did wrong?

    Main:
    apasat=0
    adcvalue=0

    GOSUB ReadButton

    IF b_level > 0 THEN
    cnt = 0
    WHILE b_level > 0
    cnt = cnt + 10
    if cnt > Long_Press THEN
    actiune = 1
    EXIT
    endif
    PAUSE 5
    GOSUB ReadButton
    WEND
    b_level = 0
    if b_act = 1 then gosub comenzi ; if button pressed is OK, no error
    ENDIF
    Goto Main


    ReadButton:
    ADCON0.1 = 1
    While ADCON0.1 = 1 : Wend

    DataW.HighByte = ADRESH
    DataW.LowByte = ADRESL
    b_level = 0
    actiune = 0
    IF DataW < 805 then
    if DataW > 50 AND DataW < 160 THEN b_level = 1
    if DataW > 180 AND DataW < 270 THEN b_level = 2
    if DataW > 290 AND DataW < 380 THEN b_level = 3
    if DataW > 400 AND DataW < 500 THEN b_level = 4
    if DataW > 540 AND DataW < 650 THEN b_level = 5
    if DataW > 690 AND DataW < 800 THEN b_level = 6

    apasat = b_level
    adcvalue=DataW

    if apasat=last_b_level then ; procedure for cheking pressed button
    b_cnt=b_cnt+1
    pauseus 200
    if b_cnt > 10 then b_act = 1 ; button pressed is OK
    endif

    last_b_level=apasat
    ENDIF

    RETURN

    ;================================================= ===========================

    comenzi:
    SEROUT GPIO.2, 2, ["You pressed button ", #apasat, " for ", #cnt, " ms", " ACTIUNE: ", #actiune, " ok ? ", #b_act, 13, 10]
    ;IF b_level=1 THEN gosub comand1
    ;IF b_level=2 THEN gosub comand2
    ;IF b_level=3 THEN gosub comand3
    ;IF b_level=4 THEN
    ; if actiune = 1 then
    ; gosub comand1
    ; else
    ; gosub comand 4
    ; endif
    ;ENDIF
    ;IF b_level=5 THEN gosub comand5
    ;IF b_level=6 THEN gosub comand6


    last_b_level=0
    b_cnt=0
    Return
    Last edited by fratello; - 2nd April 2024 at 08:34.

Similar Threads

  1. TMR1 & Button - long delay (1 min) before starting
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 14th March 2017, 13:03
  2. Long / short press button...but reading ADC
    By fratello in forum mel PIC BASIC Pro
    Replies: 37
    Last Post: - 10th July 2016, 08:37
  3. Replies: 5
    Last Post: - 26th February 2011, 05:51
  4. Replies: 1
    Last Post: - 14th October 2010, 18:33
  5. Button pressed time control
    By tanero in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 15th August 2005, 15:17

Members who have read this thread : 19

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts