Here's an off-the-cuff attempt.... although it may not be perfect, it might be enough of a clue for you to run with. Note: interpret this as pseudo-code.... probably looks a lot like C# since that's what I've been using most recently.
This works on the amount of time the button has been held, but you can apply the same logic based on the number of increments. Myself, I'd find a time-based holding of the button to be more logical from a user interface perspective.
// globals
int increment;
int direction;
int setting = 0;
timer buttonTimer; // milliseconds timer
ButtonInterruptHandler()
{
if (button == DOWNBUTTON)
direction = -1; // counting down
else if (button == UPBUTTON)
direction = 1; // counting up
buttonTimer.start; // start counting how long the button has been held
}
TimerTickInterruptHandler() // Note, this would need to be scaled down a bit using a counter to slow how often the setpoint is increased. Otherwise it would go so fast you wouldn't even see it
{
if (button == down) { // check that button is still down
if (timer.value >= 1000) // button has been held for more than a second
{
if (setting >= 1000) // set point is over 1000
{
increment = 100; // ... so we're stepping up/down by 100
}
else if (setting >= 100) // set point is over 100
{
increment = 10; // ... so we're stepping up/down by 10
}
else // set point is _under_ 100
{
increment = 1; // ... so we're stepping up/down by 1
}
}
else // button has not been held for more than a second
{
increment = 1; // ... so we're stepping up/down by 1
}
setting = setting + (increment * direction);
}
else // when we see the button back up, reset everything
{
buttonTimer.stop;
buttonTimer.reset;
}
}