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);
}
}