Hello - I feel guilty for abusing this forum but I have a question stemming from a previous issue I had much help with (thank you johnwasser) but have become kind of stuck again.
I am programming something to be used in conjunction with a touchscreen that utilizes both cores of an ESP32 (one side for interpreting whatever comes through the screen and the other for executing commands made), and as such I need void functions for their respective pages so they can be selected and run when needed.
In my previous plea for help, an admin here graciously went and coded the whole thing - though I had no idea the structure he chose to use (arguments within floats) would present issues when trying to stuff everything into a need little function to be added into the larger project file.
Here's the entire code in its current state:
int calcInt = 4;
const float Fills[] = {0.62, 0.72, 0.785, 0.907, 1.00};
float fill_a = 100; //62, 72, 78.5, 90.7, 100
float fill = fill_a / 100;
const float inchesPerMeter = 1000 / 25.4 ;
const float INCHES_PER_1000FT = 1000 * 12 ;
const float COPPER_RESISTIVITY = 1.724e-8 ;
// const char *name;
float L = 1.315;
float W = .1875;
float H = .340;
float flange = .975;
int AWG = 42;
int Ohms = 5250;
int windings = 10000;
struct Wire
{
int AWG;
float bare;
float singleInsulated;
float dooubleInsulated;
} const WireTable[] =
{
{24, 0.0201, 0.0213, 0.0233},
{25, 0.0179, 0.0190, 0.0199},
{26, 0.0159, 0.0170, 0.0178},
{27, 0.0142, 0.0153, 0.0161},
{28, 0.0126, 0.0137, 0.0144},
{29, 0.0113, 0.0123, 0.0130},
{30, 0.0100, 0.0109, 0.0116},
{31, 0.0089, 0.0097, 0.0105},
{32, 0.0080, 0.0088, 0.0095},
{33, 0.0071, 0.0078, 0.0084},
{34, 0.0063, 0.0069, 0.0075},
{35, 0.0056, 0.0062, 0.0067},
{36, 0.0050, 0.0056, 0.0060},
{37, 0.0045, 0.0050, 0.0055},
{38, 0.0040, 0.0045, 0.0049},
{39, 0.0035, 0.0039, 0.0043},
{40, 0.0031, 0.0035, 0.0038},
{41, 0.0028, 0.0031, 0.0034},
{42, 0.0025, 0.0028, 0.0030},
{43, 0.0022, 0.0025, 0.0027},
{44, 0.0020, 0.0022, 0.0025},
{45, 0.00176, 0.00192, 0.00215},
{46, 0.00157, 0.00173, 0.00196},
{47, 0.00140, 0.00158, 0.00178},
{48, 0.00124, 0.00140, 0.00155},
{49, 0.00111, 0.00124, 0.00139},
{50, 0.00099, 0.00113, 0.00128},
{51, 0.00088, 0.00103, 0.00117},
{52, 0.00078, 0.00093, 0.00107},
{53, 0.00070, 0.00079, 0.00090},
{54, 0.00062, 0.00070, 0.00082},
{55, 0.00055, 0.00064, 0.00075},
};
float calcMaxLayers(float wireDia)
{
return ((flange - W) / 2.0) / wireDia;
}
float circularArea(float diameter)
{
float radius = (diameter * Fills[calcInt]) / 2.0 ;
return radius * radius * PI;
}
float Rin (float dia)
{
return COPPER_RESISTIVITY / (12.0 * circularArea(dia));
}
float R1000ft(float dia)
{
return (COPPER_RESISTIVITY * inchesPerMeter * INCHES_PER_1000FT) / circularArea(dia);
}
float feetLengthFromResistance(float totalResistance, float bareDiameter)
{
float resistancePerThousandFeet = R1000ft(bareDiameter);
return (totalResistance / resistancePerThousandFeet) * 1000.0;
}
float quadraticRoot(float a, float b, float c)
{
float disc = b * b - 4 * a * c;
int sgnb = (b > 0 ? 1 : -1);
float temp = -0.5 * (b + sgnb * sqrt(disc));
float r1 = temp / a ;
float r2 = c / temp ;
return r1 < 0 ? r2 : r1;
}
float layersFromLength(float wireLengthFeet, float insulatedDiameter)
{
float lenInches = wireLengthFeet * 12.0;
float insulatedDiameter2 = insulatedDiameter / Fills[calcInt];
float a = PI * insulatedDiameter2;
float b = (2.0 * L) + ((PI - 2.0) * W) + (PI * (insulatedDiameter2));
float c = -((lenInches * insulatedDiameter2) / H);
return quadraticRoot(a, b, c);
}
void calcPrint() {
/*
float L = 1.315;
float W = .1875;
float H = .340;
float flange = .975;
int AWG = 42;
int Ohms = 5250;
int windings = 10000;
*/
Serial.println("-----------------------");
Serial.println("-----Bobbin Specs------");
Serial.print("Length: ");
Serial.print(L);
Serial.print(" | ");
Serial.print("Width: ");
Serial.print(W);
Serial.print(" | ");
Serial.print("Height: ");
Serial.print(H);
Serial.print(" | ");
Serial.print("Flange: ");
Serial.print(flange);
Serial.println();
Serial.println("-----------------------");
Wire w = WireTable[AWG - 24];
Serial.print("AWG:\t");
Serial.println(w.AWG);
Serial.print("Bare Wire Diameter:\t");
Serial.println(w.bare, 5);
Serial.print("Insulated Diameter:\t");
Serial.println(w.singleInsulated, 5);
Serial.print("Ohms:\t");
Serial.println(Ohms);
Serial.print("Ohms/1000ft:\t");
Serial.println(R1000ft(w.singleInsulated));
float wireFeet = feetLengthFromResistance(Ohms, w.bare);
Serial.print("Wire feet:\t");
Serial.println(wireFeet);
for (int i = 0; i < 5; i++) {
calcInt = i;
// Serial.print("\n\nBobbin Name:\t");
// Serial.println(b.name);
Serial.println("-----------------------");
Serial.print("Fill:\t");
Serial.print(Fills[calcInt] * 100);
Serial.println("%");
/*
Serial.print("Windings(nom.):\t");
Serial.println(b.windings);
*/
float layers = layersFromLength(wireFeet, w.singleInsulated);
Serial.print("Layers:\t");
Serial.println(layers);
float windingsPerLayer = ((H / w.singleInsulated) * Fills[calcInt]);
Serial.print("Windings per Layer:\t");
Serial.println(windingsPerLayer);
float windings = layers * windingsPerLayer;
Serial.print("Windings:\t");
Serial.println(windings);
float maxLayers = (calcMaxLayers(w.singleInsulated) * Fills[calcInt]);
Serial.print("MaxLayers:\t");
Serial.println(maxLayers);
if (layers > maxLayers)
{
Serial.println("Warning: Maximum layers exceeded.");
}
float maxWinds = maxLayers * windingsPerLayer;
Serial.print("maxWinds:\t");
Serial.println(maxWinds);
}; //print loop
};
void setup()
{
Serial.begin(115200);
delay(200);
calcPrint();
};
void loop() {}
Since I need to execute bits and pieces as needed, I tried stuffing all those floats with arguments (ex: float thing1(float num2, float num3) {exciting math things}) into a void function of its own to be referenced by another, and that one to be called upon from the other core when a touchscreen action is made. Arduino did not like this when compiling.
I tried going back and breaking everything into longer mathematical calculations that used floats without arguments, but the math came out wrong...
Anyway, I suppose my question is - can anyone see a better way to approach this? Is avoiding the float arguments necessary or is there another function type that can be called that will handle them?