UP/DOWN counter w/ reset, 3 push buttons (up, down, reset to 0). Count 00-99

I would like to have a counter from 00-99. with 3 buttons up/down/reset. they need to be debounced to make sure it increases or decreases by 1.

I have found a few examples online but none are intuitive. if someone has done this can you share source code? I have either a 2 piece 7 segment, or 2 single 7 segment displays.

please, any help would be appreciated!

Ok, so what have you tried so far?

Break it down into different sections, what do you need?
1 - Code that counts
2 - Code that reads buttons
3 - Code that displays a number to a 7 segment.

1 and 3 are pretty straight forward, whilst the only thing complex with 2 is debouncing (try the Bounce library).

Once the sections are identified, you can draw a simple ‘state machine’ for each - think about the different tasks each will do (the states) and what inputs control it (events). I’ve attached an example for section 3. With this approach you consider each time the loop is called to be one update cycle - where you check to see if any event has occurred.

Lets work through it.
‘Idle’ can be considered when nothing needs to be done to the display.
‘Update Number’ is when the counter gives the display a new number to show and so the state machine saves this number to a variable. Once the number changes, clearly we need to refresh the display.
‘Refresh Display’ is when you move to showing the next segment of the display (usually only one of your two digits is on at any one time to save pins). This is a timed event, so your ‘event’ can be checking the millis() timer to see if a given amount of time has passed.

From this you can write code. ‘Idle’ is basically the loop() function, and then the other two can be functions which are called when an event happens. So we get the following code structure (you can fill in the blanks).

void loop(){
  //Looping is the 'Idle' state.
  if (millis() is some value) {
    refreshDisplay(); //move to the 'refresh' state
    //and back to 'idle' state
  }
  if (counter value changed) {
    updateDisplay(new value); //move to the 'update' state
    refreshDisplay(); //move to the 'refresh' state
    //and back to 'idle' state
  }
}

byte displayValue = 0;
void refreshDisplay(){
  //Update which segment is shown - digitalWrite() for example.
}
void updateDisplay(byte val){
  displayValue = val;
}

Once you have made state machines for each of the blocks you can merge the code easily as all of the idle states will be the same (the loop() function) and all the other states will simply be some form of if statement which calls a function like in my example. You may find when you connect it all up that the event for one machine is a state for another. For example for the counter machine you will have some state which ‘changes the current count’ - clearly this is the event ‘counter value changed’ I used in my example, so you can join them up like:

if (counter should count) {
    changeCounter(some direction); //move to 'change current count'
    updateDisplay(new value); //move to the 'update' state
    refreshDisplay(); //move to the 'refresh' state
    //and back to 'idle' state
}

SimpleStateMachine.png

P.S. Read the forum rules, and don't cross-post... Your other thread:
http://forum.arduino.cc/index.php?topic=208426.0

ah right, how can i delete this post?