2015年1月8日 星期四

Merge DS18b20 & 1602 i2c pde

#include "Wire.h"
#include "LiquidCrystal_I2C.h"
#include "OneWire.h"
#include "DallasTemperature.h"

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

LiquidCrystal_I2C lcd(0x27,16,2); 
void setup()
{
 lcd.init();            
 lcd.backlight();
 lcd.print("Room Temperature");

  Serial.begin(115200);
  Serial.println("Temperature Sensor");

  sensors.begin();
}
void loop()
{
  sensors.requestTemperatures();

  Serial.println(sensors.getTempCByIndex(0));
  lcd.setCursor(5, 1);
  lcd.print(sensors.getTempCByIndex(0));
  lcd.print(" C");
  delay(1000);
}

沒有留言:

張貼留言