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 > > Just wanted to get some ideas on what the most efficient > way to do the > > following is using a polled (non-interrupt) routine: > > > > In my main program loop, the user has two pushbuttons to control the > > following modes > > > > 1. Press and release LEFT button to run mode 1 > > 2. Press and hold LEFT button for 2 seconds to run mode 2 > > 3. Press and release RIGHT button to run mode 3 > > 4. Press and hold both LEFT and RIGHT buttons for 2 > seconds to run mode > 4. > > > > I realize there are a million ways to do this, but I need > some ideas on > how > > to do this most efficiently. > > Thanks > > > > D > > > > If you draw a state diagram you will see that requirement 4 > has conflicts. A > state diagram will help you refine your protocol and identify > unique events > which you can use to simplify your code. > > Regards > Sergio Masci > > -- > http://www.piclist.com hint: The PICList is archived three different > ways. See http://www.piclist.com/#archives for details. > -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body