Datasheet

data from the CdS cell and temp is the temperature read.
You'll notice that right after each call to logfile.print() we have #if ECHO_TO_SERIAL and a
matching Serial.print() call followed by a #if ECHO_TO_SERIAL this is that debugging
output we mentioned earlier. The logfile.print() call is what writes data to our file on the
SD card, it works pretty much the same as the Serial version. If you set
ECHO_TO_SERIAL to be 0 up top, you won't see the written data printed to the Serial
terminal.
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
© Adafruit Industries https://learn.adafruit.com/adafruit-data-logger-shield Page 63 of 68