Searching \ for '[PIC]:Pushbutton Timing Routines Was: IDEAS for P' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/microchip/devices.htm?key=pic
Search entire site for: 'Pushbutton Timing Routines Was: IDEAS for P'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]:Pushbutton Timing Routines Was: IDEAS for P'
2003\05\20@095923 by Mccauley, Daniel H

flavicon
face
I came up with the following routine for the following.  Let me know what
you think.
If the pushbutton is pressed and released less than 2 seconds, the program
runs MODE1 and if the button is held for
greater than 2 seconds, SET-UP mode is run


char count;
count=0;
if (input(PB1)==0)
       {
       delay_ms(20);           // Simple Debounce
       while (input(PB1)==0)
               {
               count++;
               delay_ms(10);
               }
       if (count < 200)
               RunMode1 ();
       else
               SetUpMode ();
       }

Anyone see any problems (debouncing etc...) with this simple routine???
Thanks much.

Dan




{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body

2003\05\20@102944 by Dale Botkin

flavicon
face
On Tue, 20 May 2003, Mccauley, Daniel H wrote:

> If the pushbutton is pressed and released less than 2 seconds, the
> program runs MODE1 and if the button is held for greater than 2
> seconds, SET-UP mode is run

Pressing the button for 1.9 seconds will be seen as a short push, as will
2.56 seconds as you overflow the char used for count.  You're asking your
user to accurately time the button press to within half a second, lots of
people can't.  You may want to use a 16 bit variable for count.

Another method: when you see the button pushed, delay two seconds or so.
If the button is not still pressed, it's a short push; if it is, it's a
long push.  Maybe blink an LED or beep something to let the user know
he/she can release the button at that point, then wait until they do
release it before moving on.

Dale
--
It's a thankless job, but I've got a lot of Karma to burn off.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam@spam@mitvma.mit.edu with SET PICList DIGEST in the body

2003\05\20@104216 by John Nall

flavicon
face
One can go to http://www.htsoft.com/ and click on "Free Software" and then
on "Sample Projects."  There is a file called metro.c which has the source
code for a metronome which uses two pushbuttons, with the timing code,
etc.   Most likely cannot be used as is, but should not be hard to modify
the timing part.

John

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body

2003\05\20@112134 by Mccauley, Daniel H

flavicon
face
Thanks.  I'll probably keep the count at 255, but code it so it doesn't
overflow, or probably have it so
that when the timer reaches 2 seconds, it will automatically enter SETUP
MODE.  Thats probably better anyways, this way
the user doesn't have to time it.  Just hold the button until the mode
changes.

Dan



{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspam_OUTspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body

2003\05\20@114008 by Dale Botkin

flavicon
face
In one project, I use TIMER1 to see if it's a short or a long button press.
Clear the TIMER1 interrupt flag and TIMER1, then just watch for the
interrupt flag.  The input change will wake the PIC up and resume execution.
Then look at the button to see if it's still pressed or not.

Now a brief tap will be seen as a short press, press and hold for the other
function.

// If we get here it means the button has been pressed.
// Delay about half a second to see if it's
// a short press or a long one...
set_timer1(0);
PIR1 = 0;
while(!PIR1) {
   check_something();   // Here you can check for some other
                        // condition, like another button or
                        // switch.  You can even sleep while
                        // waiting, just turn off GPIE if you
                        // don't want to have an ISR for TIMER1.
}
if(input(BUTTON)) {      // If it's a short push
   do_something();
} else {
   do_something_else();
}

Dale

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body

2003\05\20@114436 by Sergio Masci

picon face
----- Original Message -----
From: Mccauley, Daniel H <@spam@daniel.h.mccauleyKILLspamspamLMCO.COM>
To: <KILLspamPICLISTKILLspamspamMITVMA.MIT.EDU>
Sent: Tuesday, May 20, 2003 2:54 PM
Subject: Re: [PIC]:Pushbutton Timing Routines Was: IDEAS for Pushbutton M
ode Selections


{Quote hidden}

Hi Dan,
As Dale has already pointed out the count only being 8 bits wide would give
you problems. I would suggest a further refinement:

        while (input(PB1)==0  &&  count < 200)
        {
                count++;
                delay_ms(10);
         }

        if (count < 200)
        {         RunMode1 ();
        }
        else if (count > 3)
        {        SetUpMode ();
        }

Also note that if the switch is not released before this section of code is
encounted again you may get a false trigger to RunMode1 or SetUpMode. You
should be looking for a "switch released" somewhere.

You might like to take a look at
http://www.xcprod.com/titan/XCSB/CONTRIB/lcd-04.bas This does switch
debouncing in a seperate user task and greatly simplifies dealing with
switch events and timing contraints involving multiple switches complex
states.

Regards
Sergio Masci

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body

2003\05\20@121802 by Picdude

flavicon
face
Yes.  I'm doing this in assembly currently -- being able to switch mode with "dashes" and cycle between the settings/options in each mode with "dots".  The dashes are automatic after a certain time-threshold has elapsed, but there is no limit on it (ie: if the user holds the button down for a hour, nothing else will happen).  BUT, once the threshold is reached, and the mode switches, there is a small beep that indicates this, and a very noticeable change on the display.

Cheers,
-Neil.


On Tuesday 20 May 2003 10:15, Mccauley, Daniel H scribbled:
{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email TakeThisOuTlistservEraseMEspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body

2003\05\20@123431 by erholm (QAC)

flavicon
face
Is the output on the display also in Morse code ?
:-)
Jan-Erik Soderholm.

Picdude wrote:
> ... being able to switch mode with "dashes" and cycle between
> the settings/options in each mode with "dots".

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body

2003\05\20@214759 by Sergio Masci

picon face
----- Original Message -----
From: Sergio Masci <smplEraseMEspam.....NTLWORLD.COM>
To: <EraseMEPICLISTspamMITVMA.MIT.EDU>
Sent: Tuesday, May 20, 2003 4:44 PM
Subject: Re: [PIC]:Pushbutton Timing Routines Was: IDEAS for Pushbutton M
ode Selections


>
>          if (count < 200)
>          {         RunMode1 ();
>          }
>          else if (count > 3)
>          {        SetUpMode ();
>          }
>

Sorry that should have been:

        if (count > 3)
       {
             if (count < 200)
             {         RunMode1 ();
             }
             else
             {        SetUpMode ();
             }
       }

Regards
Sergio Masci

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservEraseMEspamEraseMEmitvma.mit.edu with SET PICList DIGEST in the body

More... (looser matching)
- Last day of these posts
- In 2003 , 2004 only
- Today
- New search...