Sorry about that. Code is now in the proper format.
#include <SPI.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include <SD.h>
#include <string.h>
#define TEMP_BUS_ONE 16 // first temp: A2
#define TEMP_BUS_TWO 17 // second temp: A3
int counterTemp = 0;
float dataOne;
float dataTwo;
char test[20];
const int chipSelect = 10;
String dataString;
OneWire a2OneWire(TEMP_BUS_ONE);
DallasTemperature tempOne(&a2OneWire);
OneWire a3OneWire(TEMP_BUS_TWO);
DallasTemperature tempTwo(&a3OneWire);
File myFile;
void setup(void)
{
Serial.begin(9600);
pinMode(10,OUTPUT);
pinMode(A2,INPUT);
pinMode(A3,INPUT);
tempOne.begin();
Serial.println(tempOne.getDeviceCount(), DEC);
tempTwo.begin();
Serial.println(tempTwo.getDeviceCount(), DEC);
// SET UP SD CARD FOR WRITING
if (!SD.begin(chipSelect)) {
Serial.println("initialization failed!");
return;
} else {
Serial.println("SD card initialized");
myFile = SD.open("temp.txt", FILE_WRITE); // open file for writing
if (myFile) { // if file can be opened, write to it
Serial.println("temperature.txt file opened for writing");
} else { // if not, show an error
Serial.println("ERROR: not able to open temperature.txt");
}
}
}
void loop(void)
{
tempOne.requestTemperatures(); // Send the command to get temperatures
tempTwo.requestTemperatures();
dataString = "";
dataOne = 0;
dataTwo = 0;
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
// Serial.print(" Requesting temperatures...");
tempOne.requestTemperatures(); // Send the command to get temperatures
tempTwo.requestTemperatures();
// Serial.println("DONE");
Serial.print("Inlet Temperature is: ");
if(tempTwo.getTempCByIndex(0) < 0){
float dataTwo = 0;
Serial.println(1111);
Serial.println(floatToString(test, dataTwo, 1, 5));
}
else{
float dataTwo = tempTwo.getTempCByIndex(0);
Serial.print(floatToString(test, dataTwo, 1, 5));
}
Serial.print("Outlet Temperature is: ");
if(tempOne.getTempCByIndex(0) < 0){
float dataOne;
Serial.println(floatToString(test, dataOne, 1, 5));
}
else{
float dataOne = tempOne.getTempCByIndex(0);
Serial.println(floatToString(test, dataOne, 1, 5));
}
delay(1000);
// writeDataToCard(counterTemp, dataOne);
delay(1000);
// writeDataToCard(counterTemp, dataTwo);
delay(1000);
counterTemp++;
// write data to SD card
myFile = SD.open("temp.txt", FILE_WRITE);
myFile.print(floatToString(test, dataOne, 1, 5));
myFile.print(", ");
myFile.print(floatToString(test, dataTwo, 1, 5));
myFile.print("\n");
myFile.close();
}
char * floatToString(char * outstr, double val, byte precision, byte widthp){
char temp[16];
byte i;
// compute the rounding factor and fractional multiplier
double roundingFactor = 0.5;
unsigned long mult = 1;
for (i = 0; i < precision; i++)
{
roundingFactor /= 10.0;
mult *= 10;
}
temp[0]='\0';
outstr[0]='\0';
if(val < 0.0){
strcpy(outstr,"-\0");
val = -val;
}
val += roundingFactor;
strcat(outstr, itoa(int(val),temp,10)); //prints the int part
if( precision > 0) {
strcat(outstr, ".\0"); // print the decimal point
unsigned long frac;
unsigned long mult = 1;
byte padding = precision -1;
while(precision--)
mult *=10;
if(val >= 0)
frac = (val - int(val)) * mult;
else
frac = (int(val)- val ) * mult;
unsigned long frac1 = frac;
while(frac1 /= 10)
padding--;
while(padding--)
strcat(outstr,"0\0");
strcat(outstr,itoa(frac,temp,10));
}
// generate space padding
if ((widthp != 0)&&(widthp >= strlen(outstr))){
byte J=0;
J = widthp - strlen(outstr);
for (i=0; i< J; i++) {
temp[i] = ' ';
}
temp[i++] = '\0';
strcat(temp,outstr);
strcpy(outstr,temp);
}
return outstr;
}