Counting Button Pushes


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154

    Default Counting Button Pushes

    What is the best method of counting button pushes for a 'Mode' Select.

    I have three buttons which are used in a SELECT CASE routine.

    What i would like is say when button 2 is pushed this then sets a MODE.

    Then depending on the amount of times that button is pushed within a three second period, defines what happens next.

    So from the start, pushing button 2 once goes to routine 1, pushing it twice goes to routine 2 and pushing 3 times goes to routine 3.

    What is the most reliable method of doing this, anyone used this kind of taks before in a project.

    Many thanks.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Tissy,

    Here's a possibility.   If you do the "De-bouncing" in hardware,

    then you can use the COUNT command
    Code:
    Button2 VAR PORTC.0    ' use a pin with Schmitt Trigger input
    Presses VAR BYTE
    Down CON 0
    
    Main:
        if Button2 = Down THEN
            WHILE Button2 = Down : WEND
    '        Mode = Something
            COUNT  Button2, 3000, Presses
            BRANCHL Presses,[routine0, routine1, routine2, routine3]
            GOTO routine0
        endif
    GOTO Main
    
    '--------------
    routine0:        ' button was not pressed again
                     ' or pressed more than 3 times
    GOTO Main
    
    '--------------
    routine1:        ' pressed once
    
    GOTO Main
    
    '--------------
    routine2:        ' pressed twice
    
    GOTO Main
    
    '--------------
    routine3:        ' pressed thrice
    
    GOTO Main
    Last edited by Darrel Taylor; - 27th November 2005 at 23:01.
    DT

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. Button Push within 3 second Window
    By Tissy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 22nd December 2005, 10:06
  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