Hi there,
As I was working on the code for my latest project this morning, I have run into an obstacle; maybe it is really easy to fix and I just missed the solution or maybe it is complicated. Hopefully, you can tell me!
Basically, I have 7 integer values read from 7 different analog pins plus a temperature and humidity reading from a DHT-22.
Once the board reads the sensor values, I'll just make up some values for the purpose of demonstration, I want it to print to the serial port the following (note: the DHT-22 outputs an actual value for the temp and humidity so it would be like 15.4256 and I want it rounded to 2 decimal places)
15.43,27.52,1020,45,698,365,189,78,0
Where the first is temp, second is humidity, and the rest are variables.
//
#include <dht.h>
dht DHT;
#define DHT22_PIN 10 //digital 10, that is
// Constants that also define Pins
const int methanePin = A1;
const int propanePin = A2;
const int comonoxPin = A3;
const int nitdioxPin = A4;
const int ammoniaPin = A5;
const int codioxPin = A6;
const int ozonePin = A7;
// Variables to store sensor values in
int methane = 0;
int propane = 0;
int comonox = 0;
int nitdiox = 0;
int ammonia = 0;
int codiox = 0;
int ozone = 0;
int error = 0;
int timer = 100;
int errdelay = 2500;
void setup()
{
Serial.begin(9600);
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
for (int thisPin = 2; thisPin < 8; thisPin++) {
pinMode(thisPin, OUTPUT);
}
}
void loop()
{
// READ DATA
int chk = DHT.read22(DHT22_PIN);
switch (chk)
{
case DHTLIB_OK:
error = 0;
break;
case DHTLIB_ERROR_CHECKSUM:
error = 1;
break;
case DHTLIB_ERROR_TIMEOUT:
error = 2;
break;
default:
error = 3;
break;
}
if (error = 0) {
for (int thisPin = 2; thisPin < 8; thisPin++) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
}
// loop from the highest pin to the lowest:
for (int thisPin = 7; thisPin >= 2; thisPin--) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
}
}
else {
if (error = 1) {
digitalWrite(2, HIGH);
digitalWrite(8,HIGH);
delay(errdelay);
digitalWrite(8, LOW);
digitalWrite(2, LOW);
delay(errdelay);
}
else {
if (error = 2) {
digitalWrite(2, HIGH);
digitalWrite(5, HIGH);
digitalWrite(8, HIGH);
delay(errdelay);
digitalWrite(2, LOW);
digitalWrite(5, LOW);
digitalWrite(8, LOW);
}
else {
if (error = 3) {
digitalWrite(2, HIGH);
digitalWrite(4, HIGH);
digitalWrite(6, HIGH);
digitalWrite(8, HIGH);
delay(errdelay);
digitalWrite(2, LOW);
digitalWrite(4, LOW);
digitalWrite(6, LOW);
digitalWrite(8, LOW);
delay(errdelay);
}}}}
methane = analogRead(methanePin);
propane = analogRead(propanePin);
comonox = analogRead(comonoxPin);
nitdiox = analogRead(nitdioxPin);
ammonia = analogRead(ammoniaPin);
codiox = analogRead(codioxPin);
ozone = analogRead(ozonePin);
// DISPLAY DATA
Serial.print(DHT.humidity, 1);
Serial.print(",\t");
Serial.println(DHT.temperature, 1);
delay(1000);
}
//
// END OF FILE
//
You will note that the serial print for the Temp and Humidity is found at the bottom of the code, but I want to print all of those int values with the temp/humidity all in one comma separated chunk.
How exactly would I do this?
Thanks in advance