Hi!
I am creating an Arduino based smart watch, and I am having problems with memory.
The majority of my code is fine and doesn't take up that much space, however the timing sequence that reads the time from a Sparkfun DS1307 and projects the time on a Freetronics OLED board is taking up a huge chunk of my memory (around 30%). I was wondering if anyone had any tips on how to cut down some space. Any help/advice would be greatly appreciated
Below is the timing sequence code:
 DateTime now = RTC.now();
 String writeString;
 time.setForegroundColour(WHITE);
 writeString = "";
 writeString += String(now.hour());
 writeString += ":";
 writeString += String(now.minute());
 oled.selectFont(Droid_Sans_36);
 time.print(writeString);
 time.reset();
 writeString = "";
 writeString += String(now.day());
 writeString += "/";
 writeString += String(now.month());
 writeString += "/";
 writeString += String(now.year());
 date.setForegroundColour(WHITE);
 oled.selectFont(SystemFont5x7);
 date.print(writeString);
 date.reset();
AWOL has given you some good advice. This program (I don't have a RTC) is based on your use of the String class:
#define GOODÂ Â Â // Comment this line out to get bad version
#ifdef GOOD
char writeString[20];
#else
String writeString;
#endif
#ifdef GOOD
void UseCharArray()
{
 writeString[0] = '\0';
 strcat(writeString, "10");
 strcat(writeString, ":");
 strcat(writeString, "59");
 Serial.println(writeString);
 writeString[0] = '\0';
 strcat(writeString, "Saturday");
 strcat(writeString, "/");
 strcat(writeString, "April");
 strcat(writeString, "/");
 strcat(writeString, "2017");
 Serial.println(writeString);
}
#else
void UseStringClass()
{
 writeString = "";
 writeString += "10";
 writeString += ":";
 writeString += "59";
 Serial.println(writeString);
 writeString = "";
 writeString += "Saturday";
 writeString += "/";
 writeString += "April";
 writeString += "/";
 writeString += "2017";
 Serial.println(writeString);
}
#endif
void setup() {
 Serial.begin(9600);
#ifdef GOOD
 UseCharArray();  // Use C strings
#else
 UseStringClass(); // Use String class
#endif
}
void loop() {
}
It uses 3298 bytes of flash memory and 232 bytes of SRAM. If you uncomment the #define at the top, the code using C strings (i.e., lower case 's' using character arrays) compiles to 1918 bytes of flash and 235 bytes of SRAM.