basic button counter

i made a updown counter using this link. Arduino Digital Up/Down Counter with Grove 4-Digit Display. now if i press up button value is incressing constantly , i want to change it to once per one press then stop increament. how could i do so.

@pareshpanchal12345, you have asked a new question in a very old Thread so I have suggested to the Moderator to move it to its own Thread.

If you want help with a program please post the program code here in your next Reply. See How to use the Forum


Look at the debounce example in the IDE

To do something “once per button press”, state change detection works well.

You want to look only for the transition of the button, not one level or the other. See if this makes sense (compiles, not tested…)

#include "TM1637.h"  // include TM1637 library
#define CLK   2  // define TM1637 clock pin
#define DIO   3  // define TM1637 data pin
#define UP    4  // define up button pin
#define DN    5  // define down button pin
// initialize the TM1637 library
TM1637 tm1637(CLK, DIO);
int num = 0, prev_num = 1;

void setup() 
    // initialize the TM1637 display
    // set display brightness (from 0 to 7)
    // configure UP and DN pins as inputs
    pinMode(UP, INPUT);
    last_up = digitalRead( UP );
    pinMode(DN, INPUT);
    last_dn = digitalRead( DN );
// main loop
void loop() 
    static unsigned long
    unsigned long
    //read the buttons every 50mS
    timeNow = millis();
    if( timeNow - timeButton >= 50ul )
        timeButton = timeNow;

        button = digitalRead( UP );
        if( button != last_up )
            last_up = button;
            if( button == HIGH )
                num++;         // increment 'num'
                if(num > 9999)
                    num = 0;
        button = digitalRead( DN );
        if( button != last_dn )
            last_dn = button;
            if( button == HIGH )
                num--;         // increment 'num'
                if(num < 0)
                    num = 9999;

        if(num != prev_num)
            // if the displayed (current) number was changed
            prev_num = num;   // save current value of 'num'
            // print all data
            tm1637.display(0, num/1000);     // print thousands digit
            tm1637.display(1, num/100 % 10); // print hundreds digit
            tm1637.display(2, num/10 % 10);  // print tens digit
            tm1637.display(3, num% 10);      // print ones digit
            //delay(200);  // wait 200 milliseconds