how do I set the temperature as an integer
Chipreader7 opened this issue · comments
Hi, I am brand new at this stuff. I want to turn a fan on above a certain temperature, and a heater to turn on below a temperature. I've just read Learn Electronics with Arduino, and in that book they have you set "int" for push button states and stuff. Then you can turn on or off other items after you do a digitalRead to calculate the state of the "int".
I can't figure out how to have the Arduino read the temperature and then act in response to it. All the code examples I see simply send the temperature to the computer monitor.
Several ways:
assume the variable temperature is a float that contains the last reading
- assign the temperature to an integer variable and print that.
int myTemp = temperature; // just cut of the decimal part
Serial.println(myTemp);
- do a cast while printing
Serial.println( (int) temperature ); // just cut of the decimal part
- print the float with 0 decimals
Serial.println(temperature, 0 ); // does rounding
- use round() function
Serial.println( round(temperature) ); // explicit rounding
Note you could have used the round() function also when assigning it to an integer variable.
Normal this kind of questions should be asked on the Arduino.cc forum
Issues here are those that are specific for this library.
You may close the issue
Thanks once again Rob