Hardware Reference
In-Depth Information
digitalWrite(RTC_POW_PIN, HIGH);
digitalWrite(RTC_GND_PIN, LOW);
//Initiate the I2C bus and the RTC library
Wire.begin();
RTC.begin();
//If RTC is not running, set it to the computer's compile time
if (! RTC.isrunning())
{
Serial.println(F("RTC is NOT running!"));
RTC.adjust(DateTime(__DATE__, __TIME__));
}
//Initialize SD card
if (!SD.begin(CS_PIN))
{
Serial.println(F("Card Failure"));
return;
}
Serial.println(F("Card Ready"));
//Write column headers
File dataFile = SD.open("log.csv", FILE_WRITE);
if (dataFile)
{
dataFile.println(F("\nNew Log Started!"));
dataFile.println(F("Date,Time,Raw,Active"));
dataFile.close(); //Data isn't actually written until we
//close the connection!
//Print same thing to the screen for debugging
Serial.println(F("\nNew Log Started!"));
Serial.println(F("Date,Time,Raw,Active"));
}
else
{
Serial.println(F("Couldn't open log file"));
}
}
void loop()
{
//Get the current date and time info and store in strings
DateTime datetime = RTC.now();
year = String(datetime.year(), DEC);
month = String(datetime.month(), DEC);
day = String(datetime.day(), DEC);
hour = String(datetime.hour(), DEC);
Search WWH ::




Custom Search