Button Push within 3 second Window


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

    Default Button Push within 3 second Window

    What is the easiest way to perform the following.

    I have a routine which looks for a button push, then depending how many time the button is pushed it jumps to a routine. So for 1 button push, Routine 1, 2 Button pushes Routine 2 etc etc.

    Then within each of the Routines is a confirmation LED which flashes to show how many times you pushed the button. 2 flashes = button pushed twice.

    I then want a Confirmation GOSUB so that if the button is pushed say 3 times and the LED flashes 3 times, it gives you the opportunity to confirm your selection by pushing the button again.

    So i would like a GOSUB which gives a 3 second window where if the button is pushed again after the flashes but at anytime during this 3 second window, the selection is confirmed and the GOSUB RETURNS, if no button is pushed within the 3 seconds window, the program starts over.

    Can anyone assist with this. I'm a little stuck on how to use the timing function.

    Many thanks.

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


    Did you find this post helpful? Yes | No

    Question Something to be cleared ...

    Quote Originally Posted by Tissy
    What is the easiest way to perform the following.

    I then want a Confirmation GOSUB so that if the button is pushed say 3 times and the LED flashes 3 times, it gives you the opportunity to confirm your selection by pushing the button again.

    So i would like a GOSUB which gives a 3 second window where if the button is pushed again after the flashes but at anytime during this 3 second window, the selection is confirmed and the GOSUB RETURNS, if no button is pushed within the 3 seconds window, the program starts over.


    Many thanks.
    Hi, Tissy

    Something hurts me :

    If you push the button 2 times, and want to confirm within 3 secs ... the device will see button pushed 3 times !!!
    How do you want to understand increments from confirm pushes ???

    May be you should have two timings : 1 sec window ( i.e. ) for increments and a 2 more sec window to confirm.

    More than 3 sec will start over then.

    Hope this is your project missing part !!!

    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
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    I know what you are saying, hopefully this will clarify.

    Code:
    Clear
    DEFINE OSC 20          
    DEFINE LOADER_USED 1
    ADCON1 = %00001111
    
    
    ' ---------- [ I/O Definition ] ----------
    TRISA = %00000001       ' Set PORTA to all input
    TRISB = %10000001       ' Set PORTB (0)INPUT (1-5)OUTPUTS
    TRISC = %01000111       ' Set PORTC (0-2 input) rest Outputs
    PORTB = 0
    
    Switch      VAR PORTC.0    ' use a pin with Schmitt Trigger input
    Presses     VAR BYTE
    RedLED      VAR PORTB.1
    X           VAR BYTE
    LOOP        VAR BYTE
    
    Main:
        if Switch = 1 THEN
            WHILE Switch = 1 : WEND
            COUNT  Switch, 1500, Presses
            BRANCHL Presses,[routine1, routine2, routine3]
            GOTO MAIN
        endif
    GOTO Main
    
    '--------------
    routine0:        ' button was not pressed again
                     ' or pressed more than 3 times
    GOTO Main
    
    '--------------
    routine1:        ' pressed once
        HIGH REDled
        PAUSE 500
        LOW REDled
        GOSUB CheckButton
    GOTO Main
    
    '--------------
    routine2:        ' pressed twice
        FOR X = 1 TO 2
            HIGH REDled
            PAUSE 500
            LOW REDled
            PAUSE 500
        NEXT X
        GOSUB CheckButton
    GOTO Main
    
    '--------------
    routine3:        ' pressed thrice
        FOR X = 1 TO 3
            HIGH REDled
            PAUSE 500
            LOW REDled
            PAUSE 500
        NEXT X
        GOSUB CheckButton
    GOTO Main
    
    Flash:
        For loop = 1 to 10
            Red = 1
            Pause 50
            Red = 0
            Pause 50
        Next Loop
    Return
    
    Confirmation:
    
    Return
    Once the Switch has been pushed a number of time 1, 2 or 3, it then jumps to the routine. It is then within this routine that it looks for the confirmation Button push after the LED has flashed it corresponding number of times by going to the Confirmation subroutine.

    Hope this makes sense.

    Steve

  4. #4
    Join Date
    Oct 2005
    Posts
    28


    Did you find this post helpful? Yes | No

    Default

    How about

    Confirmation:

    confirm_flag=0
    x=0

    WHILE (x<300) and (confirm_flag=0)

    Pause 10 'check for button every 10ms
    if Switch = 1 then confirm_flag=1 ' if button pushed then set the flag
    x=x+1 ' increment the pause counter

    WEND

    Return


    comfirm_flag will be 0 if no confiirm, 1 if confirmed. Routine will exit as soon as button is pushed.

    Duncan

  5. #5
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Thanks Duncan, almost there is think.

    Indeed it does now look at the Confirmation routine, but after three seconds, it is still in the routine and presumably waiting for the button push.

    If the button is pushed, then it jumps out fine.

    I just need it so that if no button is pushed after 3 seconds it jumps back to the main code.

    Cheers

  6. #6
    Join Date
    Oct 2005
    Posts
    28


    Did you find this post helpful? Yes | No

    Default

    You should drop out of the While...wend loop when the button is pushed or if the x variable exceeds 300. AH HA! In your code, X is a byte so never exceeds 255. Either change

    (x<300) to (x<253) or change x to a word variable.

    X<253 will give you a 2.5 second delay

    Duncan

  7. #7
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Spot on, it was the BYTE and not WORD variable that was causing the confliction.

    All done now and working how i want.

    Thanks again for taking the time to help. Merry Christmas.

    Steve

Similar Threads

  1. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  2. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 22:43
  3. push button problem
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 2nd June 2005, 19:44
  4. Push Button 'Menu' to Choose Variable.
    By Tissy in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 10th March 2005, 07:00
  5. Help wanted..
    By thrix in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 17th February 2004, 23: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