Skip to content

Instantly share code, notes, and snippets.

@clive520
Created November 15, 2018 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clive520/2ff1d864d27f13dbfb755651a0e4894d to your computer and use it in GitHub Desktop.
Save clive520/2ff1d864d27f13dbfb755651a0e4894d to your computer and use it in GitHub Desktop.
DS18B20_顯示溫度於LCD_NodeMCU_ESP8266
/* Sketch was generated by motoblockly
Website: http://www.motoblockly.com
Author: www.motoduino.com
Date: Thu Nov 15 2018 20:30:05 GMT+0800
*/
#include <Wire.h>
#include <esp_LiquidCrystal_I2C.h>
#include <esp_OneWire.h>
#include <esp_DallasTemperature.h>
esp_LiquidCrystal_I2C mylcd(0x27, 16, 2);
long temp;
#define ONE_WIRE_BUS_2 2
OneWire oneWire_2(ONE_WIRE_BUS_2);
DallasTemperature sensors_2(&oneWire_2);
float Temperature_DS18B20_2(int tempUnit) {
sensors_2.requestTemperatures();
float temperature = sensors_2.getTempCByIndex(0);
if(tempUnit == 1)
return temperature;
else
return ((temperature * 1.8) + 32);
}
void setup()
{
mylcd.init();
mylcd.backlight();
sensors_2.begin();
temp = 0;
}
void loop()
{
temp = Temperature_DS18B20_2(1);
mylcd.clear();
mylcd.setCursor(0,0);
mylcd.print(temp);
delay(2000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment