I have some code that does what I want it to do except round to one decimal place when displayed on my LCD screen. Does anyone have any suggestions? The code is listed below. Thanks in advance!
// DS18B20 2 sensors with LCD
// This Arduino sketch reads DS18B20 "1-Wire" digital
// temperature sensors.
// Tutorial:
// Arduino 1-Wire Tutorial
#include <OneWire.h>
#include <DallasTemperature.h>B20
#include <LiquidCrystal.h>
#include <SPI.h>
// Connections:
// rs (LCD pin 4) to Arduino pin 12
// rw (LCD pin 5) to Arduino pin 11
// enable (LCD pin 6) to Arduino pin 10
// LCD pin 15 to Arduino pin 13
// LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int backLight = 13; // pin 13 will control the backlight
// Data wire is plugged into pin 8 on the Arduino
#define ONE_WIRE_BUS 8
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
DeviceAddress roomTemp = {
0x28, 0x9C, 0x99, 0x26, 0x04, 0x00, 0x00, 0x71 };
DeviceAddress ductTemp = {
0x28, 0xE3, 0xC5, 0xAF, 0x04, 0x00, 0x00, 0x33 };
void setup(void)
{
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(roomTemp, 10);
sensors.setResolution(ductTemp, 10);
pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
lcd.begin(16,2); // columns, rows. use 16,2 for a 16x2 LCD, etc.
lcd.clear(); // start with a blank screen
}
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
lcd.print("Error");
}
else {
tempC=tempC*1.8+32;
lcd.print(tempC);
lcd.print("/");
lcd.print(DallasTemperature::toFahrenheit(tempC));
}
}
void loop(void)
{
delay(6000);
sensors.requestTemperatures();
lcd.setCursor(0,0);
lcd.print("Room Temp: ");
printTemperature(roomTemp);
lcd.setCursor(0,1);
lcd.print("Duct Temp: ");
printTemperature(ductTemp);
}