Counter

Hello,

I am trying to create a small counter that can tell me when I reached an exact amount of pushes of a button. The code that I have can do that but when I want to change the values of pushes that I need to do I need to reupload the code, and I dont want to do that, I want to use a 4x4 keypad that I have and type the numer then press D to enter the value. I have another button to do that but I dont want to press it 500 times to get this value.

Can anyone help me doing that?

Here is my code so far:

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
#include <Keypad.h>


#define I2C_ADDR    0x27 // <<----- Add your address here.  Find it from I2C Scanner
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7


LiquidCrystal_I2C  lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);


// this constant won't change:
int ledPinFail = 53;
const int  Up_buttonPin   = 2;    // the pin that the pushbutton is attached to
const int  Down_buttonPin = 3;
int servoPin = 9;
Servo servo;

// Variables will change:

int up_buttonState = 0;         // current state of the up button
int up_lastButtonState = 0;     // previous state of the up button
int buttonPushCounter = 5;   // Adauga numar de mufari
int down_buttonState = 0;         // current state of the up button
int down_lastButtonState = 0;     // previous state of the up button
bool bPress = false;
int servoAngle = 0;
const byte ROWS = 4; 
const byte COLS = 5; 

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {A11, A10, A9, A8};
byte colPins[COLS] = {A15, A14, A13, A12};

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 


void setup()
{
  
  pinMode( Up_buttonPin , INPUT_PULLUP);
  pinMode( Down_buttonPin , INPUT_PULLUP);
  servo.write(0);
  delay(100);
  digitalWrite(servoPin, LOW);
 
  lcd.begin(16, 2);                      // initialize the lcd
  // Switch on the backlight
  lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home (); // go home
  //user interface 
  lcd.clear();
  lcd.print("   Mini-Snap"); //main title
  lcd.setCursor(0, 1);
  lcd.print("    Counter"); //main title 
  delay(1000);
  lcd.clear();
  lcd.print("  ODU Romania"); //main title
  lcd.setCursor(0, 1);
  lcd.print(" Manufacturing"); //main2 title
  delay(1000);
  lcd.clear();
  // Print a message to the LCD.
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print(" Mufari ramase:");
  lcd.setCursor(2,1);
  lcd.print(buttonPushCounter);


  servo.attach(servoPin);
}


void loop()
{
   checkUp();
   checkDown();

   if( bPress){
       bPress = false;
      lcd.setCursor(2,1);
      lcd.print("               ");
      lcd.setCursor(2,1);
      lcd.print(buttonPushCounter);
      
   }
  
}

void checkUp()
{
  up_buttonState = digitalRead(Up_buttonPin);

  // compare the buttonState to its previous state
  if (up_buttonState != up_lastButtonState) {
    // if the state has changed, increment the counter
    if (up_buttonState == LOW) {
        bPress = true;
      // if the current state is HIGH then the button went from off to on:
      buttonPushCounter++;
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  up_lastButtonState = up_buttonState;
}
void checkDown()
{
  down_buttonState = digitalRead(Down_buttonPin);

  // compare the buttonState to its previous state
  if (down_buttonState != down_lastButtonState) {
    // if the state has changed, increment the counter
    if (down_buttonState == LOW) {
        bPress = true;

      // if the current state is HIGH then the button went from off to on:
      buttonPushCounter--;

    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  down_lastButtonState = down_buttonState;
  if (buttonPushCounter == 0)
  {
    pinMode(ledPinFail, OUTPUT);
    digitalWrite(ledPinFail, HIGH);
    servo.write(90); 
    delay(100);
    
    digitalWrite(servoPin, LOW);
    delay(1000);
    
    pinMode(ledPinFail, OUTPUT);
    digitalWrite(ledPinFail, LOW);
    delay(1000);
    }

}

Maybe this will get you started.

Many other results with site-search term 'get keypad value'.