From 261e997a907e3dc456e771d513f44ba3fc208381 Mon Sep 17 00:00:00 2001 From: Phillip Burgess Date: Fri, 11 Jan 2019 17:05:42 -0800 Subject: [PATCH] Improve output formatting in examples --- .../DHT_Unified_Sensor/DHT_Unified_Sensor.ino | 61 +++++++++---------- examples/DHTtester/DHTtester.ino | 18 +++--- 2 files changed, 38 insertions(+), 41 deletions(-) diff --git a/examples/DHT_Unified_Sensor/DHT_Unified_Sensor.ino b/examples/DHT_Unified_Sensor/DHT_Unified_Sensor.ino index 4820f2e..e281578 100644 --- a/examples/DHT_Unified_Sensor/DHT_Unified_Sensor.ino +++ b/examples/DHT_Unified_Sensor/DHT_Unified_Sensor.ino @@ -11,12 +11,12 @@ #include #include -#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 -#define DHTTYPE DHT22 // DHT 22 (AM2302) -//#define DHTTYPE DHT21 // DHT 21 (AM2301) +//#define DHTTYPE DHT11 // DHT 11 +#define DHTTYPE DHT22 // DHT 22 (AM2302) +//#define DHTTYPE DHT21 // DHT 21 (AM2301) // See guide for details on sensor wiring and usage: // https://learn.adafruit.com/dht/overview @@ -26,33 +26,32 @@ DHT_Unified dht(DHTPIN, DHTTYPE); uint32_t delayMS; void setup() { - Serial.begin(9600); + 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; } @@ -61,24 +60,24 @@ void loop() { // Delay between measurements. delay(delayMS); // Get temperature event and print its value. - sensors_event_t event; + 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("%")); } } diff --git a/examples/DHTtester/DHTtester.ino b/examples/DHTtester/DHTtester.ino index ae6c41a..e0d9f27 100644 --- a/examples/DHTtester/DHTtester.ino +++ b/examples/DHTtester/DHTtester.ino @@ -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")); }