Created
November 15, 2018 14:35
-
-
Save clive520/e03617153cb1991d4805d6ff834aa671 to your computer and use it in GitHub Desktop.
DS18B20_顯示溫度於LCD02_NodeMCU_ESP8266
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Sketch was generated by motoblockly | |
Website: http://www.motoblockly.com | |
Author: www.motoduino.com | |
Date: Thu Nov 15 2018 22:28:28 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(String("Temp=") + String(temp) + String(" C")); | |
delay(2000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment