This commit is contained in:
plane000
2018-08-09 21:14:10 +01:00
parent a0f946d62e
commit c18d9afaa5
29 changed files with 14057 additions and 248 deletions

View File

@@ -1,25 +1,41 @@
#include <DHT.h>
#include <DHT_U.h>
// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>
#define DHTPIN 13
#define DHTTYPE DHT11
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
DHT dht(DHTPIN, DHTTYPE);
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
void setup() {
Serial.begin(115200);
dht.begin();
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
/*
* The setup function. We only start the sensors here
*/
void setup(void)
{
// start serial port
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
}
void loop() {
float temperature = dht.readTemperature();
if (isnan(temperature)) {
Serial.println("-1000000");
delay(500);
return;
}
Serial.println((String)temperature);
delay(30);
/*
* Main function, get and show the temperature
*/
void loop(void)
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
// After we got the temperatures, we can print them here.
// We use the function ByIndex, and as an example get the temperature from the first sensor only.
Serial.print("Temperature for the device 1 (index 0) is: ");
Serial.println(sensors.getTempCByIndex(0));
}