Datalogging shield code questions

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
madvoid
 
Posts: 9
Joined: Thu Dec 29, 2011 11:58 pm

Datalogging shield code questions

Post by madvoid »

I hope this is the right place to post this, very sorry if it isn't. I recently bought and assembled the datalogging shield and it works fine. However, I need a few clarifications about the code from the example code in the walkthrough (http://www.ladyada.net/make/logshield/l ... kthru.html)
To begin, what do these two lines do:

Code: Select all

File logfile;
and

Code: Select all

DateTime now;
Do they have something to do with classes?

Also, if I wanted to create a new file every day, would this code do that if inserted in the main loop? (The code in the if statement came from the walkthrough)

Code: Select all

if(now.hour == 0 && now.minute == 0 && now.second > 0 && now.second <= 30 ){    // 30 second sampling rate          
  char filename[] = "LOGGER00.CSV";                                                                       
  for (uint8_t i = 0; i < 100; i++) {                                                                            
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logfile = SD.open(filename, FILE_WRITE); 
      break;  // leave the loop!
    }
  }
}
Thanks in advance for any help!

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: Datalogging shield code questions

Post by adafruit_support_bill »

To begin, what do these two lines do:
The first one declares an instance of the File class. The second one declares an instance of the DateTime class.
These declarations allocate memory for these objects and associate the names "logfile" and "now" with the object instances so you can reference them in your code.

The code you post should work - as long as the loop period is exactly 30 seconds. If it is less than 30 seconds, you could get more than one new file per day. If it is more than 30 seconds, you will miss the window occasionally. (Keep in mind that there are 2880 30-second intervals in 24 hours, so even a 1 ms error will add up.) If you are using a timer to control you loop, you should be OK.

User avatar
madvoid
 
Posts: 9
Joined: Thu Dec 29, 2011 11:58 pm

Re: Datalogging shield code questions

Post by madvoid »

Ah, I see. Thank you very much for your help!

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”