Datasheet

Finally, we set the two LED pins to be outputs so we can use them to communicate with
the user. There is a commented-out line where we set the analog reference voltage. This
code assumes that you will be using the 'default' reference which is the VCC voltage for the
chip - on a classic Arduino this is 5.0V. You can get better precision sometimes by lowering
the reference. However we're going to keep this simple for now! Later on, you may want to
experiment with it.
Main loop
Now we're onto the loop, the loop basically does the following over and over:
1. Wait until its time for the next reading (say once a second - depends on what we
defined)
2. Ask for the current time and date froom the RTC
3. Log the time and date to the SD card
4. Read the photocell and temperature sensor
5. Log those readings to the SD card
6. Sync data to the card if its time
Timestamping
Lets look at the first section:
void loop(void)
{
DateTime now;
// delay for the amount of time we want between readings
delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));
digitalWrite(greenLEDpin, HIGH);
// log milliseconds since starting
uint32_t m = millis();
logfile.print(m); // milliseconds since start
logfile.print(", ");
#if ECHO_TO_SERIAL
Serial.print(m); // milliseconds since start
Serial.print(", ");
#endif
// fetch the time
now = RTC.now();
// log time
logfile.print(now.get()); // seconds since 2000
logfile.print(", ");
© Adafruit Industries https://learn.adafruit.com/adafruit-data-logger-shield Page 80 of 85