Essentialy I want it to run through the first for loop:
for (;millis() < startTime + 2000UL;)
and when the condition is meet switch to the other for loop:
for (;millis() < startTime + 5000UL;)
in both loops in need the data to be written to my SD card.
My code ran just fine when I was writing to the Serial monitor.
void setup()
{
// Sets analog pins to input
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
// Sets analog pins to input
pinMode(13, INPUT);
pinMode(12, OUTPUT);
// Opens the serail connection
Serial.begin(250000);
}
void loop()
{
unsigned long startTime;
unsigned long intreval = 2000UL; // 120 seconds
unsigned long previousInterval = 0;
unsigned long intreval1 = 5000UL; // 60 seconds
unsigned long previousInterval1 = 0;
while (digitalRead(13) == HIGH)
{
startTime = millis();
for (; millis() < startTime + 2000UL;)
{
char tuf[10];
digitalWrite(12, LOW);
sprintf(tuf, "low ");
Serial.print(tuf);
dataLog();
if (digitalRead(13) == LOW)
{
break;
}
//(digitalWrite(12) == HIGH);
//void dataLog();
//delay(60000);
}
for (; millis() < startTime + 5000UL;)
{
char tuf1[10];
digitalWrite(12, HIGH);
sprintf(tuf1, "high ");
Serial.print(tuf1);
dataLog();
if (digitalRead(13) == LOW)
{
break;
}
}
}
}
void dataLog()
{
char buf[100];
char buf1[50];
//Pressure transducers
int PT1A;
int PTT1;
int PT1B;
int PT1C;
unsigned long runMillis = millis();
unsigned long allSeconds = millis() / 1000;
int runHours = allSeconds / 3600;
int secsRemaining = allSeconds % 3600;
int runMinutes = secsRemaining / 60;
int runSeconds = secsRemaining % 60;
// Sets values of incoming analog pin data to transducer nnumbers
PT1A = analogRead(A0); // Reads data from analog pin A0
PTT1 = analogRead(A1); // Reads data from analog pin A1
PT1B = analogRead(A2); // Reads data from analog pin A2
PT1C = analogRead(A3); // Reads data from analog pin A3
sprintf(buf, "Runtime%02d:%02d:%02d ", runHours, runMinutes,
runSeconds);
sprintf(buf1, "PT1A: %d; PTT1: %d; PT1B: %d; PT1C: %d", PT1A, PTT1, PT1B, PT1C);
Serial.print(buf);
Serial.println(buf1);
}