 
 void error(char mess[]){
     // TO DO
-    Serial.print("Shit");
+    serialOut(mess);
+    digitalWrite(RED_LED_PIN, HIGH);
+    delay(500);
+    digitalWrite(GREEN_LED_PIN, HIGH);
+    delay(500);
 }//error
 
 void printArray(float array[], int arraySize){
     for(int i=0; i<arraySize; i++){
         Serial.println(array[i]);
-    }
+        Serial.flush();
+        //delay(SERIAL_DELAY);
+    }
+}
+
+void serialOut(char output[]){
+#if TEST
+    Serial.println(output);
+    //delay(SERIAL_DELAY);
+    Serial.flush();
+#endif
+    return;
 }
 
 void test(){
 
+    char buff[25];
+    char *time = buff;
+
     float *voltages, *amps, *temps;
-    char *time;
     voltages = readVoltage();
     amps = readAmp();
     temps = readTemp();
-    time = readTime();
+    readTime(time);
     printArray(voltages, 4);
     printArray(amps, 4);
     printArray(temps, 3);
-    Serial.println(time);
-    int timeAdd = time;
-    Serial.println(timeAdd);
-    Serial.println(filename);
-    int fileAdd = filename;
-    Serial.println(fileAdd);
+    serialOut(time);
+    serialOut("Old filename:");
+    serialOut(filename);
     newFile();
-    Serial.println(filename);
-    fileAdd = filename;
-    Serial.println(fileAdd);
-    delay(1000);
-
+    serialOut("New filename:");
+    serialOut(filename);
+    //delay(100);
+    sleep();
     return;
 }
 
 void setup() {
 
     Serial.begin(9600);
-    Serial.println();
+    serialOut("");
 
     pinMode(RED_LED_PIN, OUTPUT);
     pinMode(GREEN_LED_PIN, OUTPUT);

    Serial.print("Initializing SD card...");
    // make sure that the default chip select pin is set to
    // output, even if you don't use it:
    pinMode(10, OUTPUT);

    // see if the card is present and can be initialized:
    if (!SD.begin(chipSelect)) {
        error("Card failed, or not present");
    }
    Serial.println("card initialized.");



    // create a new file
    if (! SD.exists(filename)) {
        // only open a new file if it doesn't exist
        TGC_logfile = SD.open(filename, FILE_WRITE); 
    }
    

    if (! TGC_logfile) {
        error("couldnt create file");
    }

    Serial.print("Logging to: ");
    Serial.println(filename);

    // connect to RTC
    Wire.begin();  
    if (!RTC.begin()) {
        TGC_logfile.println("RTC failed");
    Serial.println("RTC failed");
    }
#endif


    return temps;
}//readTemp

void readTime(char *time){
    // TO DO
    #if TEST
        serialOut("readTime");
    #endif
    //static char *time;
    //char *temp;

    int randNumber = random(100);
    sprintf(time, "%09d", randNumber);
    //time = &temp;
    //serialOut(time);

    //strcat(time, str(randNumber));

    return time;
}//readTime
