Count button presses


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Nov 2007
    Posts
    42

    Default Count button presses

    I have my project setup to check for button presses on a pin. Simple IF *** = 0 THEN ****

    I would like to be able to count the button presses like if 3 button presses are made within a certain time, it would set a variable to 3. If pressed 5 times, set said variable to 5 and so on.

    Right now my code is setup to just add to the current variable every time the button is pressed. The problem is that I have it flash an LED to confirm what setting it's on and since it immediately add's to the variable, then checks the variable, you can't just tap the button 4 quick times and jump to setting 4.

    Any help would be great.

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Talking

    Hi,

    Only solution : , index on LCD or Bargraph or LED Display of the number !!!

    Or use a "Rainbow led" ... and display with resistor's code !!!

    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 " !!!
    *****************************************

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Hi. If I understand correctly, something like this should allow you to push the button numerous times while advancing your mode with each push. Unfortunately, I’m at work now & can’t test it. It looks to me like it should work.

    START:
    CLEAR 'ALL VARIABLES = 0
    IF PORTA.0 = 1 THEN START 'BUTTON NOT PUSHED STAY HERE

    MODE:
    LET TIMER = 0 ‘RESET TIMER
    LET MODENUMBER = (MODENUMBER + 1) 'ADVANCE MODE

    WAITFORRELEASE:
    PAUSE 25 'DEBOUNCE
    IF PORTA.0 = 0 THEN WAITFORRELEASE 'BUTTON STILL PUSHED WAIT HERE

    BUTTONTIMER:
    IF PORTA.0 = 0 THEN MODE 'ADVANCE MODE IF BUTTON PUSHED AGAIN
    LET TIMER = (TIMER + 1)
    PAUSE 10
    IF TIMER >= 500 THEN SIGNALMODE 'AFTER 5 SECONDS SIGNAL THE MODE NUMBER
    GOTO BUTTONTIMER

    SIGNALMODE:
    HIGH PORTB.0 'LIGHT UP LED OR BEEP PIEZO BUZZER
    PAUSE 250
    LOW PORTB.0 'OFF LED OR SOUNDER
    PAUSE 250
    LET SIGNAL = (SIGNAL + 1)
    IF SIGNAL < MODENUMBER THEN SIGNALMODE 'KEEP FLASHING OR BEEPING
    GOTO (YOUR MAIN PROGRAM)

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    If you have only 1 push button, you could use an internal timer/counter. This one will increase each time you press on the switch (may need some external debouncing). You could also use an interruptible pin, says INT0, and within your ISR, you increase your counter value and process the Debouncing.

    A timer interrupt, or polling a timer overflow to check the Counter value, and you're all set.
    Last edited by mister_e; - 4th May 2009 at 15:59.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Nov 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    I will try the example above. If anyone else has any other suggestions please let me know.

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. COUNT is not counting again
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 19th June 2009, 04:52
  3. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  4. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 22:43
  5. Button Push within 3 second Window
    By Tissy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 22nd December 2005, 10:06

Members who have read this thread : 0

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