Single button function


Closed Thread
Results 1 to 40 of 41

Hybrid View

  1. #1
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Talking Slb 0587

    Hi, Vtt

    A look Here, may be ...

    http://www.electronique-diffusion.fr...lb0587&x=2&y=8

    ...

    some chips still on the market !!! ... and in my drawers ... LOL !

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  2. #2
    Join Date
    Feb 2013
    Posts
    1,124


    Did you find this post helpful? Yes | No

    Default Re: Slb 0587

    Due to my lack of knowledge, when facing same problem, I did the following - while user keeps button pressed, value of needed variable is being increased and value of waiting variable reset. As user releases the button, waiting variable is being increased, and after it reaches some value (say for 2 seconds), next chunk of code is required. I'd like to do the same with long press, but still can't figure how.

    Any ideas to add long press detection to this code?

    Code:
    setuploop:
    if but2=0 then
    dlycnt=dlycnt+1 'increase debounce variable while button is pressed
    
    pause 1
    endif
    
    if BUT2=1 and dlycnt>100 then 'if button pressed long enough
    dlycnt=0
    high buz 'enable buzzer pin
    menuitem=menuitem+1
    lcdout $fe,1, #menuitem, " pressed "
    pause 5
    low buz 'disable buzzer
    endif
    goto setuploop

  3. #3
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Single button function

    IF Button = Pressed THEN
    WHILE Button = Pressed
    LOOP
    ENDIF

  4. #4
    Join Date
    Feb 2013
    Posts
    1,124


    Did you find this post helpful? Yes | No

    Default Re: Single button function

    I did it in the different way:
    Code:
    setuploop:
    if but2=0 then
    dlycnt=dlycnt+1 'increase debounce variable while button is pressed
    ticker=ticker+1
    pause 1
    endif
    if ticker>1500 and  BUT2=0 then gasvla 'if long pressed, then exit and (or) go to selector item
    if BUT2=1 and dlycnt>100 then  'if short pressed, then do the rap
    ticker=0
    dlycnt=0
    menuitem=menuitem+1  'this is incremental variable, substitute another next time you need it
    lcdout $fe,$c0, " selection: " #menuitem," "  'debug just for case
    pause 1
    endif
    goto setuploop

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Single button function

    I did a setup to check for...... short press, then 2 second or 5 second then long press to enter program mode, for next for the timing, then go on to next check and goto's

    Code:
     FOR A1= 1 TO 5        '<.1 SECONDS FOR TIMER
     PAUSE 3 
     GOSUB RDSW
     if SWCH=0 then start
     NEXT A1
     HIGH 2
    read 1,A4 :PAUSE 10: C1=60*A4:C2=C1      
                        
     FOR A1 = 1 TO 100       '2 SECONDS FOR 8 HR
     PAUSE 8
     GOSUB RDSW
     if SWCH=0 then TIMER
     NEXT A1
     C1=28800      '8 HRS
     HIGH 5                       
     
     FOR A1 = 1 TO 100        'CHECK FOR PROGRAM 5 SEC TOTAL
     PAUSE 40
     GOSUB RDSW
     if SWCH=0 then TIMER
     NEXT A1 
     LOW 2:GOTO PROGRAM

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default Re: Single button function

    All the above methods block the program execution. If this is not a problem then it I guess ok.

    But if the PIC must do other things, it is better to have a ticker in a timer interrupt routine and count up when a key is pressed. Periodically check the ticker for the required value and decide what to do.

    That way, program does not stay in a closed loop until button release.

    Ioannis

Similar Threads

  1. Sony SIRC IR Issue
    By Ryan7777 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th August 2015, 08:10
  2. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  3. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 22:43
  4. Pushbutton code routine suggestions?
    By jessey in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd September 2005, 01:02
  5. Button subfunction 16F628
    By Jųan in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th August 2005, 16:44

Members who have read this thread : 1

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