I'm trying to trouble shoot a problem with my code and narrowed it down to my if statement not working with a fraction.
The below code does not work and returns 0
for(float i=0; i <= 1; i += .0001){
t += .0001;
if(t >= 1/440){ //Fraction
t = 0;
}
Serial.println(t*100);
delay(100);
}
But when I replace the 1/440 with its decimal equivalent (.0022727) it works fine and counts from 0 to 2.2
for(float i=0; i <= 1; i += .0001){
t += .0001;
if(t >= 0.0022727){ //Decimal
t = 0;
}
Serial.println(t*100);
delay(100);
}
If there is a simple way to use a fractional value instead of a decimal value it would make my application much similar. Thanks.
programming
tag after all, so I think programming questions are OK. Especially if beginners to Arduino maybe think that the Arduino has different rules to C++.