Value control by holding down button

Hello i have a small problem in my code.While i am holding down a button i need a value to increase / decrease continuously.But when i upload the code and hold down the button the timer works fine but the value only increases by 1 every time the button gets held down.
Thank you in advance the code can be found below.

#include <EEPROM.h>
#include <Wire.h>
#include <Arduino.h>
#include <Adafruit_ADS1015.h>
#include <Adafruit_PWMServoDriver.h>
#include "Adafruit_MCP23017.h"
#include <LiquidCrystal_I2C.h>
#include "VARIABLES.h"
#include "DRV8825.h"
//MODULES
Adafruit_ADS1115 ads; // ADC
Adafruit_MCP23017 mcp; // IO Expander
Adafruit_PWMServoDriver ServoDriver= Adafruit_PWMServoDriver(); //Servo Driver
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD
DRV8825 stepper(200,6,7, 2, 3, 4, 5); // Stepper Driver



void setup()
{
    Serial.begin(9600); // DB
    stepper.begin(RPM); 
    stepper.enable();   
    lcd.begin();
    lcd.createChar(0,arrow1);
    lcd.createChar(1,arrow2);
    ads.begin();
    // ADC Sensitivity
    ads.setGain(GAIN_TWOTHIRDS);
    mcp.begin();
    ServoDriver.begin();
    ServoDriver.setPWMFreq(60);
    // MCP Setup Pins
    mcp.pinMode(2,INPUT); // ENCODER CLK PIN
    mcp.pinMode(3,INPUT); // ENCODER DATA  PIN
    mcp.pinMode(4,INPUT); // ENCODER BUTTON PIN
    mcp.pinMode(5,INPUT); // JOYSTICK 1 BUTTON
    
    
}
void loop()
{  
   normal_mode();
 }
void normal_mode()
{
read_controls();
  //Serial.println(J1Yangle); //DB
  
  if(J1Xangle>=89 || J1Xangle <=93)
  {
    //Serial.println(J1Xangle); //DB
    if(J1Xangle!= currentAngle[0])
    {
        if(currentAngle[0] <= J1Xangle)
        {
          //Serial.print("CurrentAngle Is  :");   //DB
          //Serial.print(currentAngle[0]);        //DB
          //Serial.print("   Desired Angle Is  ");//DB
          //Serial.println(J1Xangle);             //DB
          drive_servo(0,currentAngle[0]);
          drive_servo(1,currentAngle[0]);
          currentAngle[0]++;
        }
        else if(currentAngle[0] >= J1Xangle)
        {
          drive_servo(0,currentAngle[0]);
          drive_servo(1,currentAngle[0]);
          currentAngle[0]--;
        }
    }
  }
  if(J1Yangle>=89 || J1Yangle <=93)
  {
    //Serial.println(J1Yangle); //DB
    if(J1Yangle!= currentAngle[1])
    {
        if(currentAngle[1] <= J1Yangle)
        {
          //Serial.print("CurrentAngle Is  :");   //DB
          //Serial.print(currentAngle[1]);        //DB
          //Serial.print("   Desired Angle Is  ");//DB
          //Serial.println(J1Yangle);             //DB
          drive_servo(2,currentAngle[1]);
          currentAngle[1]++;
        }
        else if(currentAngle[1] >= J1Yangle)
        {
          drive_servo(2,currentAngle[1]);
          currentAngle[1]--;
        }
    }
  }
  if(J2Xangle>=89 || J2Xangle <=93)
  {
    //Serial.println(J2Xangle); //DB
    if(J2Xangle!= currentAngle[2])
    {
        if(currentAngle[2] <= J2Xangle)
        {
          //Serial.print("CurrentAngle Is  :");   //DB
          //Serial.print(currentAngle[2]);        //DB
          //Serial.print("   Desired Angle Is  ");//DB
          //Serial.println(J2Xangle);             //DB
          drive_servo(3,currentAngle[2]);
          currentAngle[2]++;
        }
        else if(currentAngle[2] >= J2Xangle)
        {
          drive_servo(3,currentAngle[2]);
          currentAngle[2]--;
        }
    }
  }
  if(J2Yangle>=89 || J2Yangle <=93)
  {
    //Serial.println(J2Yangle); //DB
    if(J2Yangle!= currentAngle[3])
    {
        if(currentAngle[3] <= J2Yangle)
        {
          //Serial.print("CurrentAngle Is  :");   //DB
          //Serial.print(currentAngle[3]);        //DB
          //Serial.print("   Desired Angle Is  ");//DB
          //Serial.println(J2Yangle);             //DB
          drive_servo(4,currentAngle[3]);
          currentAngle[3]++;
        }
        else if(currentAngle[3] >= J2Yangle)
        {
          drive_servo(4,currentAngle[3]);
          currentAngle[3]--;
        }
    }
  }
  read_controls();
  if(J2ButtonPressed==true && HoldtimerJB2==0)
  {
    HoldtimerJB2=millis();
  }
  if(J2ButtonPressed==false)
  {
    HoldtimerJB2=0;
  }
  if(HoldtimerJB2-millis() >=100)
  {
    if(StepperAngle+1<=360)
    {
      StepperAngle=StepperAngle+1;
      drive_stepper(microstepping,StepperAngle);
      //Serial.print("Stepper Angle  ");  //DB
      //Serial.print(StepperAngle);       //DB
      //Serial.print("    Hold Time  "); //DB
      //Serial.println(HoldtimerJB2);      //DB
    }
  }
  if(J1ButtonPressed==true && HoldtimerJB1==0)
  {
    HoldtimerJB1=millis();
  }
  if(J1ButtonPressed==false)
  {
    HoldtimerJB1=0;
  }
  if(HoldtimerJB1-millis() >=100)
  {
     if(StepperAngle-1>=0)
    {
      Serial.print("Stepper Angle  ");  //DB
      Serial.print(StepperAngle);       //DB
      Serial.print("    Hold Time  "); //DB
      Serial.println(HoldtimerJB1);      //DB
      StepperAngle=StepperAngle-1;
      drive_stepper(microstepping,StepperAngle);
    }
  }
}
void read_controls()
{
  //Reading ADC
  J1X = ads.readADC_SingleEnded(0);
  J1Y = ads.readADC_SingleEnded(1);
  J2X = ads.readADC_SingleEnded(2);
  J2Y = ads.readADC_SingleEnded(3);
  //Serial.print(J1X);                //DB
  //Serial.print("              ");   //DB
  //Serial.println(J1Y);              //DB
  // 24430 MAX VALUE
  // 30 MIN VALUE
  // Map Values to angles 
  J1Xangle=map(J1X,30,23500,0,180);
  J1Yangle=map(J1Y,30,23500,0,180);
  J2Xangle=map(J2X,30,23500,0,180);
  J2Yangle=map(J2Y,30,23500,0,180);
  //Serial.print(J1Xangle);            //DB
  //Serial.print("              ");    //DB
  //Serial.println(J1Yangle);          //DB

  //Read State of Buttons

  
  // Joystick Button 1 Timer
  if(mcp.digitalRead(0)==LOW)
  {
    //Serial.println("BUTTON 1 PRESSED"); //DB
    J1ButtonPressed=true;
  }
  else
  {
    J1ButtonPressed=false;
  }

  
  // Joystick Button 1 Timer
  if(mcp.digitalRead(1)==LOW)
  {
    //Serial.println("BUTTON 2 PRESSED"); //DB
    J2ButtonPressed=true;
  }
  else
  {
    J2ButtonPressed=false;
  }


  // Button 1 Timer
  if(mcp.digitalRead(5)==LOW)
  {
    //Serial.println("BUTTON 3 PRESSED"); //DB
    Button1Pressed=true;
  }
  else
  {
    Button1Pressed=false;
  }


  // Button 2 Timer
  if(mcp.digitalRead(6)==LOW)
  {
    //Serial.println("BUTTON 4 PRESSED"); //DB
    Button2Pressed=true;
  }
  else
  {
    Button2Pressed=false;
  }

  //Button 3 With Debouncing
  debounce(7);
  
  if(buttonPressed==true)
  {
    buttonPressed=false;
    Button3Pressed=true;
  }
  else
  {
    Button3Pressed=false;
    buttonPressed=false;
  }

  //Button 3 With Debouncing
  debounce(8);
  
  if(buttonPressed==true)
  {
    buttonPressed=false;
    Button4Pressed=true;
  }
  else
  {
    Button4Pressed=false;
    buttonPressed=false;
  }
}

While i am holding down a button i need a value to increase / decrease continuously

"continuously" doesn't make sense. Increasing or decreasing once on every iteration of loop() might.

      StepperAngle=StepperAngle+1;

Did you ever wonder why the language used to program the Arduino was not called C=C+1?

Thank you in advance the code can be found below.

Some of it, anyway. So, some of the answer is:
There is a problem on line

First of all let me clear some things out to make troubleshooting easier.

The original code replaced

StepperAngle = StepperAngle +1; with StepperAngle++

I just wrote it like this to make troubleshooting easier (changing the increments etc)

further more the whole code used would just take up space since my only problem is here.(all the other pieces of code work)

Also this piece of code nests inside a function running in void loop() so i can rule out problems that occur when summoning a function incorrectly.

Also this piece of code nests inside a function running in void loop() so i can rule out problems that occur when summoning a function incorrectly.

You don't "run" a function. You call a function.

If you don't want to post all of your code, that is you prerogative. But, if you don't, don't expect help.

Yeah i got the terminology wrong ill post the whole code.

I have posted the complete code now you should be able to better understand the code.

ChristosS:
I have posted the complete code now you should be able to better understand the code.

We do not like for people to overwrite their first post. It makes people that commented on the original post look like fools. Do NOT do that again.

  if(J1Xangle>=89 || J1Xangle <=93)
  if(J1Yangle>=89 || J1Yangle <=93)

Or? Shouldn't that be And?

Why does normal_mode() call read_controls() twice?

Where is the debounce() function?

How long does it take between calls to normal_mode()?

But when i upload the code and hold down the button the timer works fine but the value only increases by 1 every time the button gets held down.

Now that we've seen more of the code, perhaps you can comment on what "the timer" is that works fine, and which value only increases by 1.

I did not think about that you are absolutely right.
To make it a bit more clear

  1. J1X/Yangle is produce by a joystick that gets read by an I2C ADC (in read_controls function) and then the ADC value gets mapped between 0-180 degrees.So the J1X/Yangle is basically the mapped output of the ADC.
    I do not want the motor ro move in the joystick is in the center position that is why i am asking the motor to be moved if the angle is not in the "center position values"

2)The read_controls() being called twice is a mistake i did not notice till now thanks for that.

3)the debounce function follows. Basically when its being called the given pin is being debounced.

int debounce(int buttonPin)
{
  buttonState=mcp.digitalRead(buttonPin);
  if (buttonState != oldButtonState){
    if (millis () - buttonPressTime >= debounceTime){ // debounce
      buttonPressTime = millis ();  // when we closed the switch 
      oldButtonState =  buttonState;  // remember for next time 
      if (buttonState == LOW)
      {
        //Serial.println ("Button closed"); // DEBUGGING: print that button has been closed
        buttonPressed = true;
      }
      else 
      {
        //Serial.println ("Button opened"); // DEBUGGING: print that button has been opened
        buttonPressed = false;
      }  
}
  }
}
  1. if i had to assume it takes about 2ms for the normal_mode() function to be called again since it was last executed.

(i say this based on a test i did where i printed the HoldTimerJB2 variable)

  1. The timer i am referring to is the HoldTimerJB1 variable which counts the time that the button is pressed

3)the debounce function follows. Basically when its being called the given pin is being debounced.

So, you have several pins to be debounced, but you (think you can) use one variable to hold the current state of all pins, one variable to hold the previous state of all pins, and one variable to hold the time when all the pins last changed state.

I'd ask how that's working for you, but I already know the answer.

  1. if i had to assume it takes about 2ms for the normal_mode() function to be called again since it was last executed.

After seeing the debounce routine, which throws a big-ass monkey wrench into the works, the answer to this question no longer matters.

  1. The timer i am referring to is the HoldTimerJB1 variable which counts the time that the button is pressed

Again, the mess that is the debounce() function renders your code, and observations, useless.

You really MUST fix the debounce() function to use arrays of current states, previous states, and previous event times. Pass the function the index to check, not the pin number, or give it a way to determine the index based on the pin number (which will require an array of pin numbers).

I do not have just one variable... i reset the variable int the debounce function everytime i call it and depending on the result of the function i set correct variable for the button.
Here is an example.

 debounce(7);
  
  if(buttonPressed==true)
  {
    buttonPressed=false;
    Button3Pressed=true;
  }
  else
  {
    Button3Pressed=false;
    buttonPressed=false;
  }

EDIT : I know that the code in this state is at best junky but i will optimize it once i get the thing working.

EDIT : I know that the code in this state is at best junky but i will optimize it once i get the thing working.

Get it "working" by simply using delay(10) in place of your debounce() function. The switches should not be bouncing longer than that.

I am sorry i was not clear about my intentions here. I want it to get it working without delays only using timers. Not for learning purposes but because i need the code to be executed as fast as possible.

I want it to get it working without delays

Then fix the debounce() function. You need to track the state of every pin independently. You can NOT use one current state, one previous state, and one time variable to debounce multiple pins.

The debounce function works. The pin entered gets debounced and if the button was pressed the variable resets so the function can debounce the next pin.

ChristosS:
The debounce function works. The pin entered gets debounced and if the button was pressed the variable resets so the function can debounce the next pin.

Using the previous state of the first pin. That is wrong.

Please excuse my ability to explain but that is what i am trying to tell you. That the boolean variable gets used multiple times but after every time it gets reset.The state of the pin after the debounce function gets stored in a variable specific to the pin debounced.

ChristosS:
Please excuse my ability to explain but that is what i am trying to tell you. That the boolean variable gets used multiple times but after every time it gets reset.The state of the pin after the debounce function gets stored in a variable specific to the pin debounced.

Please explain exactly how that happens.

The debounce() routine reads the current state of a pin. It then compares that to the value in oldButtonState, which may not be the previous state of the pin that was just read. I can't see anywhere in your code where the value in oldButtonState gets copied anywhere else.

So, when you debounce pin 8, after debouncing pin 7, you are comparing the time that pin 8 changed state to the time that pin 7 changed state and you are comparing the current state of pin 8 to the previous state of pin 7.

Oh my god... when you first mentioned the debounce function i only thought of the buttonState variable completely ignoring the old state variable. I know see the problem. I will fix the debounce function or just incorporate the code inside the read_controls function for the buttons that need to be debounced then i will reply with hopefully what would be the solution for the next person with this problem.
Thank you.