I'm doing a fan control project. I want to mimic something like the afterburner fan curve control. So far I've done the following:
double x [6] = {0,25,35,60,80,100};
double y [6] = {0,0,25,50,100,100};
double yc[5];
double xc[5];
double k[5];
void setup() {
Serial.begin(115200);
Serial.println("Started serial and entered the setup");
for (int i=0 ; i<=4 ; i++ ){
Serial.println();
Serial.print("Calculating k for ");
Serial.print(i);
Serial.print(" line");
yc[i]=(y[i+1]-y[i]);
Serial.println();
Serial.print("yc=");
Serial.print(yc[i]);
xc[i]=(x[i+1]-x[i]);
Serial.println();
Serial.print("xc=");
Serial.print(xc[i]);
if(yc[i]==0){
Serial.println();
Serial.print("Y is 0 for this point, so k is also");
k[i]=0;
}
if(xc[i]==0){
Serial.println();
Serial.print("We have a problem huston, I'm trying to devide by 0");
}
k[i]=((yc[i])/(xc[i]));
Serial.println();
Serial.print("Calculated:");
Serial.print(k[i]);
}
Serial.println();
Serial.print("Finished setup, entering loop");
}
void loop() {
if (Serial.available() > 0) {
int inputValue = Serial.read();
Serial.println();
Serial.println("I got this:")
Serial.print(inputValue);
}
}
Quite basic so far. I need to now check if the inputted X is somewhere between X points to apply the correct upper bond and k and calculate the y. What would be the best approach to do this fast as to not strain the processor unnecessary with numerous if-s?
If anyone also has any experience with this and would like to pitch in with a better way to do this I'm all ears.