 
 void setup() {
 
+    #if defined(SERIAL_DEBUG)
     Serial.begin(9600);
+    #endif
 
     // DS1307 CLK 
     setSyncProvider(RTC.get);   

    if(timeStatus()!= timeSet) {
        // CLK error
        char error[] = "clock error" ;
		char line2[]= "***" ;
        Serial.println(error);
		lcd_print(error,line2);	
        for(;;);
    }

    // initialize SD card
    pinMode(SS, OUTPUT);
    if (!SD.begin(chipSelect)) {
        Serial.println("Card failed, or not present");
        // don't do anything more:
        while (1) ;
    }
    
	// LCD
	
    Alarm.timerRepeat(10, log_data);

}

void lcd_print(char* line1, char* line2) {

    pinMode(LCD_PIN, OUTPUT);
    digitalWrite(LCD_PIN, HIGH);
    lcd.begin(16,2);       
    lcd.clear();
    // line1
    lcd.setCursor(0,0);
    lcd.print(line1); 
    lcd.setCursor(0,1);
    lcd.print(line2); 
}

void log_data() {

    char ts[18] ;
	char data[12] ;
	get_sensor_data(ts,data);

    dataFile = SD.open("yuktix.log", O_CREAT | O_WRITE | O_APPEND);
    if (! dataFile) {
      Serial.println("error opening yuktix.log");
      // Wait forever since we cant write data
      while (1) ;
    }

    // write to SD card
    dataFile.print(ts);
    dataFile.print(",");
    dataFile.println(data);
	micro_delay(20);
    dataFile.close();  
    micro_delay(20);

    int hh = hour();
    int mm = minute();
	char line2[6] ;
	sprintf(line2,"%02d:%02d",hh,mm);
	
	lcd_print(line2,data);

}

void get_sensor_data(char* ts, char* data) {

    // timestamp
    int hh = hour();

  Alarm.delay(1000);
 
}

