mirror of
https://github.com/adafruit/DHT-sensor-library.git
synced 2023-10-23 22:20:38 +03:00
Improve output formatting in examples
This commit is contained in:
parent
bdd2756ed1
commit
261e997a90
@ -11,7 +11,7 @@
|
||||
#include <DHT.h>
|
||||
#include <DHT_U.h>
|
||||
|
||||
#define DHTPIN 2 // Pin which is connected to the DHT sensor.
|
||||
#define DHTPIN 2 // Pin connected to the DHT sensor.
|
||||
|
||||
// Uncomment the type of sensor in use:
|
||||
//#define DHTTYPE DHT11 // DHT 11
|
||||
@ -29,30 +29,29 @@ void setup() {
|
||||
Serial.begin(9600);
|
||||
// Initialize device.
|
||||
dht.begin();
|
||||
Serial.println("DHTxx Unified Sensor Example");
|
||||
Serial.println(F("DHTxx Unified Sensor Example"));
|
||||
// Print temperature sensor details.
|
||||
sensor_t sensor;
|
||||
dht.temperature().getSensor(&sensor);
|
||||
Serial.println("------------------------------------");
|
||||
Serial.println("Temperature");
|
||||
Serial.print ("Sensor: "); Serial.println(sensor.name);
|
||||
Serial.print ("Driver Ver: "); Serial.println(sensor.version);
|
||||
Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
|
||||
Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" *C");
|
||||
Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" *C");
|
||||
Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" *C");
|
||||
Serial.println("------------------------------------");
|
||||
Serial.println(F("------------------------------------"));
|
||||
Serial.println(F("Temperature Sensor"));
|
||||
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name);
|
||||
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
|
||||
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
|
||||
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("°C"));
|
||||
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("°C"));
|
||||
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("°C"));
|
||||
Serial.println(F("------------------------------------"));
|
||||
// Print humidity sensor details.
|
||||
dht.humidity().getSensor(&sensor);
|
||||
Serial.println("------------------------------------");
|
||||
Serial.println("Humidity");
|
||||
Serial.print ("Sensor: "); Serial.println(sensor.name);
|
||||
Serial.print ("Driver Ver: "); Serial.println(sensor.version);
|
||||
Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
|
||||
Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println("%");
|
||||
Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println("%");
|
||||
Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println("%");
|
||||
Serial.println("------------------------------------");
|
||||
Serial.println(F("Humidity Sensor"));
|
||||
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name);
|
||||
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
|
||||
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
|
||||
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("%"));
|
||||
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("%"));
|
||||
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("%"));
|
||||
Serial.println(F("------------------------------------"));
|
||||
// Set delay between sensor readings based on sensor details.
|
||||
delayMS = sensor.min_delay / 1000;
|
||||
}
|
||||
@ -64,21 +63,21 @@ void loop() {
|
||||
sensors_event_t event;
|
||||
dht.temperature().getEvent(&event);
|
||||
if (isnan(event.temperature)) {
|
||||
Serial.println("Error reading temperature!");
|
||||
Serial.println(F("Error reading temperature!"));
|
||||
}
|
||||
else {
|
||||
Serial.print("Temperature: ");
|
||||
Serial.print(F("Temperature: "));
|
||||
Serial.print(event.temperature);
|
||||
Serial.println(" *C");
|
||||
Serial.println(F("°C"));
|
||||
}
|
||||
// Get humidity event and print its value.
|
||||
dht.humidity().getEvent(&event);
|
||||
if (isnan(event.relative_humidity)) {
|
||||
Serial.println("Error reading humidity!");
|
||||
Serial.println(F("Error reading humidity!"));
|
||||
}
|
||||
else {
|
||||
Serial.print("Humidity: ");
|
||||
Serial.print(F("Humidity: "));
|
||||
Serial.print(event.relative_humidity);
|
||||
Serial.println("%");
|
||||
Serial.println(F("%"));
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ DHT dht(DHTPIN, DHTTYPE);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.println("DHTxx test!");
|
||||
Serial.println(F("DHTxx test!"));
|
||||
|
||||
dht.begin();
|
||||
}
|
||||
@ -44,7 +44,7 @@ void loop() {
|
||||
|
||||
// Check if any reads failed and exit early (to try again).
|
||||
if (isnan(h) || isnan(t) || isnan(f)) {
|
||||
Serial.println("Failed to read from DHT sensor!");
|
||||
Serial.println(F("Failed to read from DHT sensor!"));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -53,17 +53,15 @@ void loop() {
|
||||
// Compute heat index in Celsius (isFahreheit = false)
|
||||
float hic = dht.computeHeatIndex(t, h, false);
|
||||
|
||||
Serial.print("Humidity: ");
|
||||
Serial.print(F("Humidity: "));
|
||||
Serial.print(h);
|
||||
Serial.print(" %\t");
|
||||
Serial.print("Temperature: ");
|
||||
Serial.print(F("% Temperature: "));
|
||||
Serial.print(t);
|
||||
Serial.print(" *C ");
|
||||
Serial.print(F("°C "));
|
||||
Serial.print(f);
|
||||
Serial.print(" *F\t");
|
||||
Serial.print("Heat index: ");
|
||||
Serial.print(F("°F Heat index: "));
|
||||
Serial.print(hic);
|
||||
Serial.print(" *C ");
|
||||
Serial.print(F("°C "));
|
||||
Serial.print(hif);
|
||||
Serial.println(" *F");
|
||||
Serial.println(F("°F"));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user