Button press and press & hold how to ?


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Robson View Post
    Hello grandpa,

    Maybe this can be good for you.

    Code:
    Button VAR PORTB.0 ' Your Input switch
    Loop    VAR WORD
    
    InputButton:
    IF Button = 1 THEN Check4Button
    GOTO InputButton
    
    Check4Button:
    FOR Loop = 0 TO 1000 ' 1 Second
         PAUSE 1
         IF Button = 0 THEN Stop ' If button was released before 1 Sec = short keypress
    NEXT Loop
    IF Button = 1 THEN Park ' If button was hold longer than 1 Sec = long keypress
    GOTO InputButton
    
    Stop:
    ' Here is your code
    
    Park:
    ' Here is your other code
    
    END
    regards Rob


    Something to pay attention for:


    Button and Stop are reserved words =>> they are commands.

    You may want to rename them as Btn and Stp.

    ============================
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  2. #2
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    Oh of course. How I forget it ;-x
    Maybe it was too late 4 me ...
    Code:
    Btn VAR PORTB.0 ' Your Input switch
    LoopTime VAR WORD
    
    InputButton:
    PAUSE 20 ' Button delay or use DEFINE BUTTON_PAUSE before
    IF Btn = 1 THEN Check4Button
    GOTO InputButton
    
    Check4Button:
    FOR LoopTime = 0 TO 1000 ' 1 Second
        PAUSE 1
        IF Btn = 0 THEN Stp ' If button was released before 1 Sec = short keypress
    NEXT LoopTime
    IF Btn = 1 THEN Park ' If button was hold longer than 1 Sec = long keypress
    GOTO InputButton
    
    Stp:
    ' Here is your code
    
    Park:
    ' Here is your other code
    
    END
    Last edited by Robson; - 21st August 2007 at 08:47.

Similar Threads

  1. 4 Bytes one button press
    By Dennis in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 15th January 2010, 22:36
  2. Giving power to MCU upon button press - Good Idea?
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 21st July 2009, 07:34
  3. multi functions button press
    By malwww in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 27th May 2009, 00:12
  4. Using Sleep
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th August 2008, 04:05
  5. Sleep until button press?
    By kevj in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th October 2007, 03:47

Members who have read this thread : 2

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