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
Posted: Sat Nov 20, 2010 9:19 pm
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.
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