 #include <SD.h>
 
 
-#define DHT11_PIN 3 
+#define DHT11_PIN 2 
 
 dht11 DHT11;
-const int chipSelect = 10;
+const int chipSelect = 9;
 File dataFile;
 
 

    int hh = hour();
    int mm = minute();
    int ss = second();

    // time
    sprintf(buffer,"%d:%d:%d,",hh,mm,ss);

    int dht11_code = DHT11.read(DHT11_PIN);
    if(dht11_code != 0 ) {
        // error
        sprintf(buffer+9,"%7s","error");

    } else {
        sprintf(buffer+9,"%-3d,%-3d",DHT11.temperature, DHT11.humidity);
    }

    buffer[16] = '\0' ;
    // @debug
    Serial.println(buffer);
    // write to SD card
    dataFile.println(buffer);
    dataFile.flush();
    
}

// param n is to ensure n*10 ms delay


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

}
