How to clean up variable declarations?

Guys,

I am writing code for a pretty large project that uses almost all of the pins on -two- arduino dues. At the top of my code I have so many variable declarations that it takes up half of my screen. I am wondering if there is a way to clean this up, or hide it somehow to reduce the amount of stuff my eyes has to process when coding.

I was able to write a function that initializes all of my I/O pins in my setup function which effectively hides quite a bit of clutter, but I am not able to put anything at the very start of my program into a function because it throws an error.

Any ideas on how to tidy it up? Below I have attached the front page of my code. The functions I call are on different tabs.

//delta kinematics variables
//THIS PROGRAM JOGS THE DELTA ROBOT
//LOAD ON ARDUINO #1
float SB, l, sP, WB, UB, wP, uP, a, b, c, x = 0, y = 0, z = 0, C[3], L[3];
int ZBLstp = 22, ZBLdir = 23, ZBRstp = 24, ZBRdir = 25, ZFLstp = 26, ZFLdir = 27, ZFRstp = 28, ZFRdir = 29; //z axis motor pins
int J2stp = 30, J2dir = 31, J1Fstp = 32, J1Fdir = 33, J1Bstp = 34, J1Bdir = 35; //J1/J2 motor pins
int DBstp = 36, DBdir = 37, DFRstp = 38, DFRdir = 39, DFLstp = 40, DFLdir = 41, wriststp = 42, wristdir = 43; //delta robot motor pins
int J1Fprox = 44, J1Bprox = 46, J2prox = 49, ZBLprox = 45, ZBRprox = 47, ZFLprox = 51, ZFRprox = 53, DFLprox = 48, DFRprox = 50, DBprox = 52; //proximity switch pins
int inputpins[] = {20, 21, 18, 19, 16, 17, 14, 15, 12, 13, 11, 8, 10, 9}; //jogging input pins
int J1[] = {20, 21}; //J1 pins (positive, negative)
int J2[] = {18, 19}; //J2..
int J3[] = {16, 17}; //J3..
int DX[] = {14, 15}; //Delta robot X
int DY[] = {12, 13}; //Delta robot Y
int DZ[] = {11, 8}; //Delta robot Z
int DR[] = {10, 9}; //Delta robot R
float DFL_UR_stps = 0.0, DFR_UR_stps = 0.0, DB_UR_stps = 0.0; //delta robot unrounded destination steps
float d_conversion = 4199.475, delta_dir_inc = .001;
long DFL_R_stps = 0, DFR_R_stps = 0, DB_R_stps = 0; //delta robot rounded destination steps
long DFL_counter = 0, DFR_counter = 0, DB_counter = 0; //tracks delta motor positions (microsteps)

void setup()
{
  DeltaKinVars();//calculate the kinematics variable constants
  Pin_Init();//initialize all pins
  Serial.begin(9600);
  pinMode(6, OUTPUT);//enable
  FPK();
  L_calc();
  DFL_counter = L[0] * d_conversion;
  DFR_counter = L[1] * d_conversion;
  DB_counter = L[2] * d_conversion;
  Serial.println("");
  Serial.print("DFL COUNTER: ");
  Serial.println(DFL_counter);
  ZERO();
}

void loop()
{
  JOG_DELTA();
  digitalWrite(6, LOW);
  if (digitalRead(ZBRprox) == HIGH) //debug
  {
    Serial.println("");
    Serial.print("L0: ");
    Serial.println(L[0]);
    Serial.print("L1: ");
    Serial.println(L[1]);
    Serial.print("L2: ");
    Serial.println(L[2]);
    Serial.print("x: ");
    Serial.println(x);
    Serial.print("y: ");
    Serial.println(y);
    Serial.print("z: ");
    Serial.println(z);
    Serial.print("DFL_R_stps: ");
    Serial.println(DFL_R_stps);
    Serial.print("DFL_counter: ");
    Serial.println(DFL_counter);
    //Serial.print("DFR_R_stps: ");
    //Serial.println(DFR_R_stps);
    delay(500);
  }
}

Do all those need to be global? If they are only going to be used local to a function, define it there. It will take up less permanent RAM.

Make a .h file that defines structs or classes (with .cpp file) to organize the details. Use the IDE tabs.

KeithRB:
Do all those need to be global? If they are only going to be used local to a function, define it there. It will take up less permanent RAM.

Yea this is something I need to get better with. My knowledge extends to knowing what what global/local variables are, but I haven't practiced using them much. Thank you for the response!

I would say you have it backwards. Make all your variables local and only convert them to global if you need to share information between functions, or if it is state you want to maintain like the positions of servos.

Not making it smaller but certainly "cleaning it up", use better variable names. J2stp for example is just rubbish... And once you start to number variables, arrays!

Also, the "Arduino default" is to camelCaseVariables and UpperCamelCaseConsts.

And use a variable type that's big enough but not bigger. So for example a byte for pins. And make the variable const if you don't change it during runtime (like pins or settings).

And I see a lot of repetition in the names. For example all with a dir and step prefix. Just put that into (a level of) an array. And add en enum for easy access IF you don't loop over it. For example:

const byte MotorPins = {5, 6};
enum dir_stp_t{DIR, STEP};