Hi all!
I'm trying to concatenate some strings, doubles, and ints into one big string. First, I tried to convert the doubles and ints into char arrays, and then add those to strings:
dtostre(avgTemp, 5, 2, tempString);
int daysLeft = 21 - round(daysGoneBy);
itoa(daysLeft, dayString, 10);
dtostre(h, 5, 2, humidString);
int lastTurn = round((timeNow-timeThen)/3600000);
itoa(lastTurn, eggTurnString, 10); */
String string1="Currently, the temperature is";
String string2="*C and the humidity is";
String string3="%. The eggs were last turned ";
String string4=" hours ago, and there are ";
String string5=" days until hatch. Cheep cheep!";
String FinalTweet = string1 + tempString + string2 + humidString + string3 + eggTurnString + string4 + dayString + string5;
Then, after reading this (http://arduino.cc/en/Tutorial/StringAdditionOperator), I decided to try and add them without converting them first:
int daysLeft = 21 - round(daysGoneBy);
int lastTurn = round((timeNow-timeThen)/3600000);
String string1="Currently, the temperature is";
String string2="*C and the humidity is";
String string3="%. The eggs were last turned ";
String string4=" hours ago, and there are ";
String string5=" days until hatch. Cheep cheep!";
String FinalTweet = string1 + avgTemp + string2 + h + string3 + lastTurn + string4 + daysLeft + string5;
Neither compiled. The error for the first was:
invalid conversion from int to char*
MainCode:209: error: invalid conversion from 'char*' to 'unsigned char'
MainCode:209: error: initializing argument 4 of 'char* dtostre(double, char*, unsigned char, unsigned char)'
Error for the second was:
MainCode:220: error: ambiguous overload for 'operator+' in 'string1 + avgTemp'
StringSumHelper& operator+(const StringSumHelper&, int)
StringSumHelper& operator+(const StringSumHelper&, unsigned char)
StringSumHelper& operator+(const StringSumHelper&, char)
timeNow, timeThen, daysGoneBy, avgTemp, and h are doubles
dayString, humidString, eggTurnString, and tempString are char arrays of different sizes
"MainCode" is the name of my file
Thank you!!!