CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

A button with several functions

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bauche



Joined: 06 Nov 2010
Posts: 22
Location: montreal qc

View user's profile Send private message Send e-mail

A button with several functions
PostPosted: Fri Nov 19, 2010 8:36 pm     Reply with quote

Hello, does anyone have an idea about how to make a button with two functions?
Code:

if (variable _1 >=1)
{
PIN_A3 = STOP;
}
else
{
PIN_A3 = SET_TIMER;
}

and also if you press the button for more than two seconds it
changes state.

Code:

#define  START       (input(PIN_A3))

Thank you for any hints...
vinniewryan



Joined: 29 Jul 2009
Posts: 154
Location: at work

View user's profile Send private message MSN Messenger

PostPosted: Fri Nov 19, 2010 10:09 pm     Reply with quote

Well, if I understand correctly, something like this should do the trick:

Code:


int8 secondspassed=0;
int16 buttontimer=0;
int1 button=0;

if(input(PIN_A3)) //button has been pressed
{
   button=1;
   
   if(buttontimer>xxx) //how ever many timer cycles are in 1 second
      //or you can use a hardware timer
   {
      secondspassed++;
      buttontimer=0;
   }
   else
   {
      buttontimer++;
   }
}
else
{
   if(button==1) //button has been released
   {
      button=0;

      if(secondspassed<2) //button was NOT held down for 2 seconds
      {
         if(variable_1>=1)
         {
            stop();
         }
         else
         {
            set_timer();
         }
      }
      else //the button HAS been held down for 2 seconds
      {
          //do something here
      }
   }
   else //the button is not currently being pressed
   {
      secondspassed=0; //reset
   }
}



This code is not tested, but it's a general idea of how you would call different functions depending on different button conditions.
_________________
Vinnie Ryan
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Nov 20, 2010 9:19 pm     Reply with quote

Quote:
Does anyone have an idea about how to make a button with two functions?
If you press the button for more than two seconds it changes state.

This thread has code, and links to other code, for a button with several features:
http://www.ccsinfo.com/forum/viewtopic.php?t=42027
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group