I am a programming novice and not sure how to clear out the unused memory. I don't really care about optimal performance just that it can work for a couple of hours without crashing. Below is my loop function which I assembled looking at the examples on my sensors. Any advice on how to use that library to make my program work?
void loop()
{
bool newdata = false;
unsigned long start = millis();
// Every second we print an update
while (millis() - start < 1000)
{
if (feedgps())
newdata = true;
}
// Get Temperature data
sensors.requestTemperatures();
float temp1c = sensors.getTempCByIndex(0);
float temp1f=temp1c*1.8+32;
// GET PRESSURE Data
int raw = 0;
for (int i=0; i<16; i++){
raw += analogRead(A0);
}
raw /=16;
float cooked = cook(raw);
// Define - get GPS data
float flat, flon;
unsigned long age, date, time, chars = 0;
unsigned short sentences = 0, failed = 0;
gps.f_get_position(&flat, &flon, &age);
// print Serial Data in CSV format for screen
print_date(gps);
Serial.print(", ");
Serial.print(temp1c);
Serial.print(", ");
Serial.print(temp1f);
Serial.print(", ");
//Serial.print("PSI"); // Temp PSI placeholder
Serial.print(cooked, 2);
Serial.print(", ");
print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, 2);
Serial.print(", ");
print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 9, 5);
Serial.print(", ");
print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 9, 4);
Serial.print(", ");
print_float(gps.f_altitude(), TinyGPS::GPS_INVALID_F_ALTITUDE, 8, 2);
Serial.print(", ");
print_float(gps.f_course(), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
Serial.print(", ");
print_float(gps.f_speed_mph(), TinyGPS::GPS_INVALID_F_SPEED, 6, 2);
Serial.print(", ");
print_str(gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(gps.f_course()), 6);
Serial.println();
// Write same data to file in CSV format
// Ignore print_ functions for complexity
myFile = SD.open("HEROCKET.CSV", FILE_WRITE);
if (myFile) {
fprint_date(myFile, gps);
myFile.print(", ");
myFile.print(temp1c);
myFile.print(", ");
myFile.print(temp1f);
myFile.print(", ");
//myFile.print("PSI"); // Temp PSI placeholder
myFile.print(cooked, 2);
myFile.print(", ");
//print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, 2);
myFile.print(gps.satellites());
myFile.print(", ");
//print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 9, 5);
myFile.print(flat);
myFile.print(", ");
//print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 9, 4);
myFile.print(flon);
myFile.print(", ");
//print_float(gps.f_altitude(), TinyGPS::GPS_INVALID_F_ALTITUDE, 8, 2);
myFile.print(gps.f_altitude());
myFile.print(", ");
//print_float(gps.f_course(), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
myFile.print(gps.f_course());
myFile.print(", ");
//print_float(gps.f_speed_mph(), TinyGPS::GPS_INVALID_F_SPEED, 6, 2);
myFile.print(gps.f_speed_mph());
myFile.print(", ");
//print_str(gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(gps.f_course()), 6);
myFile.print(TinyGPS::cardinal(gps.f_course()));
myFile.println();
}
myFile.close();
}