Im getting stuck in a while loop because Im having trouble running a calculation on some sensor values. When I read my four sensors values and compare the ratio of the first two to the second two, I keep getting 0.00, no matter what the values are. Here's my code:
while ( ( (frontleft + frontright) / (backleft + backright) <= 0.8 ) || ( (frontleft + frontright) / (backleft + backright) > 1.2) ) {
if (backleft + backright > frontleft + frontright) {
myStepper2.step(10);
}
if (backleft + backright < frontleft + frontright) {
myStepper2.step(-10);
}
int backleft = analogRead(A0);
int backright = analogRead(A1);
int frontleft = analogRead(A2);
int frontright = analogRead(A3);
Serial.print("Backleft Reading: ");
Serial.println(backleft);
Serial.print("\n");
Serial.print("BackRight Reading: ");
Serial.println(backright);
Serial.print("\n");
Serial.print("Frontleft Reading: ");
Serial.println(frontleft);
Serial.print("\n");
Serial.print("Frontright Reading: ");
Serial.println(frontright);
Serial.print("\n");
float ratio = (frontleft + frontright) / (backleft + backright);
float math = (5 + 6) / (4 + 5);
Serial.print("Math: ");
Serial.println(math);
Serial.print("Ratio: ");
Serial.println(ratio);
Serial.print("\n");
delay(500);
}
Im getting values for my sensors (backleft, backright, frontleft, frontright), but 'ratio' always comes out 0.00. Because of that, Im getting trapped in the loop I believe. What's going on here?
Also, just to check, I added 'math' float as that quick calculation, but I'm getting a value of 1.00 in Serial Monitor. Why? It should be 1.222.