milesburton / Arduino-Temperature-Control-Library

Arduino Temperature Library

Home Page:https://www.milesburton.com/w/index.php/Dallas_Temperature_Control_Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

@Chipreader7

Several ways:
assume the variable temperature is a float that contains the last reading

  1. assign the temperature to an integer variable and print that.
int myTemp = temperature;    // just cut of the decimal part
Serial.println(myTemp);
  1. do a cast while printing
Serial.println( (int) temperature );   // just cut of the decimal part
  1. print the float with 0 decimals
Serial.println(temperature, 0 );   // does rounding
  1. 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