Hardware Reference
In-Depth Information
minute = String(datetime.minute(), DEC);
second = String(datetime.second(), DEC);
//Concatenate the strings into date and time
date = year + "/" + month + "/" + day;
time = hour + ":" + minute + ":" + second;
//Gather motion data
raw = analogRead(IR_PIN);
//If the value changes by more than 75 between readings,
//indicate movement.
if (abs(raw-raw_prev) > 75)
active = true;
else
active = false;
raw_prev = raw;
//Open a file and write to it.
if (active || update_time == 20)
{
File dataFile = SD.open("log.csv", FILE_WRITE);
if (dataFile)
{
dataFile.print(date);
dataFile.print(F(","));
dataFile.print(time);
dataFile.print(F(","));
dataFile.print(raw);
dataFile.print(F(","));
dataFile.println(active);
dataFile.close(); //Data isn't actually written until we
//close the connection!
//Print same thing to the screen for debugging
Serial.print(date);
Serial.print(F(","));
Serial.print(time);
Serial.print(F(","));
Serial.print(raw);
Serial.print(F(","));
Serial.println(active);
}
else
{
Serial.println(F("Couldn't open log file"));
}
update_time = 0;
}
delay(50);
update_time++;
}
Search WWH ::




Custom Search