  Loop
 /****************************/
 void loop(){
+  static unsigned long pollMoment;
+  static byte polls;
 
-  if (timeStatus() == timeSet) {
-    if ( pollingLoopCounter == POLLING_INTERVAL ){
+  if (timeStatus() == timeSet) { // Wait for time stamp before doing anything else
+    if ( millis() >= pollMoment + (unsigned long)POLLING_INTERVAL * 1000UL) { // Checking clock with millis() is more accurate than counting loops. Because the numbers can get large, they are converted to UL.
+      pollMoment = millis(); // millis() returns the number of milliseconds that passed since the processor started.
       pollData();
-      pollingLoopCounter = 0;
+      polls++;
     }
-    pollingLoopCounter++;
-    if ( logLoopCounter == LOG_INTERVAL ){
+    if ( polls == POLLS_PER_LOG ){
       logData();
-      logLoopCounter = 0;
+      polls = 0;
     }
-    logLoopCounter++;
     if (Serial.available()) {
       processSerialCommandInput();   
     }
   }
-  else {
+  else { 
     if (Serial.available()) {
       processDateInput();   
     }
   }
-  delay(1000);
+  delay(100); // Delay prevents serial commands getting chopped up in separate characters.
 }
 
 /****************************

      Serial.println(sLog);
    }
    else{
      Serial.println("> No log yet.");
    }
  }  
}

/*
  Log environmental data to CSV
 
  This sketch sents values temperature, humidity, CO2 and the digital filter
  setting to the serial port in CSV format. After uploading, open the serial
  monitor (ctrl+shift+m) and follow instructions. The CSV data can be copied
  and pasted into a spreadsheet. In order to keep memory and storage
  consumption low, but not average out extremes, the sketch polls more
  frequently than it logs. As the log is kept in RAM, only a around 9 data
  points can be recorded. As opening the serial monitor resets the Arduino,
  logs can only be read if the computer is connected during the whole logging
  period. Depending on your computer, you may put it on standby. Just don't
  reset the serial connection. When memory is full, logs are no longer saved.
  Some messy last entries may show up.

  created 13 Feb 2015
  by Koos Looijesteijn
 
  This code is in the public domain.
 	 
  Upon first use, the sensor must be calibrated. If you don't get proper
  readings, do this: 1) Upload the SetToPolling sketch - Because the library
  is made for polling. 2) Move the sensor to an area with fresh air 3) Upload
  the Calibrate sketch 4) Upload this sketch again.
  
  For logging in Fahrenheit, just replace all instances of 'Celsius'.
*/
