Button press or not


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2006
    Posts
    747

    Default Button press or not

    Hello,

    I have an application where the user pushes a press button to start the menu and also uses the same push button to scoll through the values. It should work fine if the button is press for under a second. But is there anyway to control the lenght of the pull down time? Lets says the user keep pressing on the button for 10 seconds, its will probable go through all the menus as fast as it can !! is there any way to prevent this ???

    thanks

    K

  2. #2


    Did you find this post helpful? Yes | No

    Default

    When detecting the pushbutton press, just wait until you detect that it has been released, then continue.
    Also suggest you add some de-bounce code to stop extra/false detections.

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    Hello,

    I have an application where the user pushes a press button to start the menu and also uses the same push button to scoll through the values. It should work fine if the button is press for under a second. But is there anyway to control the lenght of the pull down time? Lets says the user keep pressing on the button for 10 seconds, its will probable go through all the menus as fast as it can !! is there any way to prevent this ???

    thanks

    K
    Hi lerameur, Ken?
    I've gotten old, that's why I call my wife Dear, better than Hey You !
    To answer your question, yes force the menue to exit the subroutine after the last selection or allow it to repeat once then exit. Here is a link to one of Melanies programs involving button presses and multi function buttons, I am pretty sure she covered this topic a couple of times.
    http://www.picbasic.co.uk/forum/showthread.php?t=3423
    be sure to use the "Special" Google link to search INSIDE the forum.
    http://www.google.com/custom?hl=en&c...ch&sitesearch=
    it really works a Treat.
    Cheers, I hope this is helpful.
    JS
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    Hi,
    I guess i have one more question about the while loop for a program fromMelanie:
    Here is a snip if the code

    While MyButton=0 'PORTB.0, zero when not pressed, 1 when pressed
    If ButtonPress<255 then ButtonPress=ButtonPress+1
    Pause 50 ' This is also our Debounce value
    Wend

    The problem with this is that I have a battery charger Subroutine in there. Therefore the code looks like this.

    While MyButton=0 'PORTB.0, zero when not pressed, 1 when pressed
    If ButtonPress<255 then ButtonPress=ButtonPress+1
    Pause 50 ' This is also our Debounce value
    Gosub Charge_Battery ' takes hours to charge
    Wend

    Therefore MyButton is going to increment very rarely. Almost never. In Melanie's code there is also the option of Longpress, which requires to hold the button for a few seconds. This is what I need, How do I incorporate this Longpress into my program.??
    Here is Melanie's full code:
    MyButton var PortB.0 ' Your Button can be anywhere
    ' Connect between PIC pin and Vss
    ' Use Weak Pull-Up or Resistor to Vdd

    ButtonPress var BYTE ' Button Counter Variable

    LongPress con 20 ' Change this value for desired SET
    ' function trip-point in 50mS steps
    ' Currently set for 1 Second


    MainLoop:
    LCDOut $FE,1,"Go Press..."
    ButtonLoop:
    Gosub GetButton
    If ButtonPress>0 then
    If ButtonPress=1
    LCDOut $FE,1,"Short Press"
    else
    LCDOut $FE,1,"Long Press"
    endif
    Pause 1000
    Goto MainLoop
    endif
    Goto ButtonLoop

    '
    ' Subroutine weighs-up users finger
    ' in multiples of 50mS
    ' Constant LONGPRESS determines boredom level
    ' -------------------------------------------
    ' on Exit...
    ' ButtonPress=0 - No Press
    ' ButtonPress=1 - Short Press
    ' ButtonPress=2 - Long Press
    GetButton:
    ButtonPress=0
    While MyButton=0 'PORTB.0, zero when not pressed, 1 when pressed
    If ButtonPress<255 then ButtonPress=ButtonPress+1
    Pause 50 ' This is also our Debounce value
    Wend
    If ButtonPress>0 then
    If ButtonPress=>LongPress then
    ButtonPress=2
    else
    ButtonPress=1
    endif
    endif
    Return

  5. #5
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    I did not take the time to download your code and test it.
    I would allow the button press (mainloop?) to run and collect the button press data before the gosub executes and/or write my code to allow the gosub to check for additional buttonpresses by short cycle returns or use interrupts to detect the button press.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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