Hello,
I am writing some code to measure the loop current in a 4-20mA control loop. Everything is working well, except the float I send to the serial monitor is only two digits after the decimal, i.e. "8.92". Never 1 place, never 3 places, always 2.
I have tried a number of things to increase the number of places to the right of the decimal, but so far no luck. Why does this always spit out x.xx?
Here is the snippet that does the analog read and prints the result. (Note, the steps that multiply and divide val2 are just some things I am using to keep straight in my head how the value is processed. I know I could do it in one step).
int analogPin = A3;
int val = 0; // variable to store the value read
float val2 = 0.000;
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(115200); // setup serial
}
// the loop function runs over and over again forever
void loop() {
val = analogRead(analogPin); // read the input pin
val2=val*12.350;
val2=val2/1000.000;
val2=val2*2.000;
Serial.println(val2); // debug value
}