Creating a reference time

Hello everybody,

I am using the arduino to take sensor readings from a series of 9 thermistors. I want to use a time that each reading was (approximately) taken at and Im not quite sure the best way to use the millis or icros function to do it. Logically I want to:

1 look for a digital pin to go high (do nothing until this happens)
2 start a timer
3 carry out a code until i hit the reset button

the problem is that i am using a ttl signal that is on for 5ms and off for 2 ms (or something like that) I dont want the code to ever be able to go back into that while loop where the TTL might be low. heres my code just incase you want to see what i have done so far.

void setup()
{
Serial.begin(9600);
pinMode(TTLPin, INPUT);
Serial.println("#S|CPBLTST|[]#");
Serial.println("#S|THRMLOG|[Time;Vin0;Vin1;Vin2;Vin3;Vin4;Vin5;Vin6;Vin7;Vin8]#");
int tStart = micros();
}

void loop(){
while(TTLPin== LOW){
}

Vin0 = analogRead(v0Pin); Vin1 = analogRead(v1Pin); Vin2 = analogRead(v2Pin);
Vin3 = analogRead(v3Pin); Vin4 = analogRead(v4Pin); Vin5 = analogRead(v5Pin);
Vin6 = analogRead(v6Pin); Vin7 = analogRead(v7Pin); Vin8 = analogRead(v8Pin);

char buffer[7];

Serial.print("#S|THRMLOG|[");
tTest = micros() - tStart;
Serial.print(itoa((tTest), buffer, 10));
Serial.print(";");
Serial.print(itoa((Vin0), buffer, 10));
Serial.print(";");
Serial.print(itoa((Vin1), buffer, 10));
Serial.print(";");
Serial.print(itoa((Vin2), buffer, 10));
Serial.print(";");
Serial.print(itoa((Vin3), buffer, 10));
Serial.print(";");
Serial.print(itoa((Vin4), buffer, 10));
Serial.print(";");
Serial.print(itoa((Vin5), buffer, 10));
Serial.print(";");
Serial.print(itoa((Vin6), buffer, 10));
Serial.print(";");
Serial.print(itoa((Vin7), buffer, 10));
Serial.print(";");
Serial.print(itoa((Vin8), buffer, 10));
Serial.print(";");
Serial.println("]#");

michaud85:
1 look for a digital pin to go high (do nothing until this happens)

while (digitalRead(someButton) == LOW);

2 start a timer

To what end?

You can use millis() to record a "time stamp" and go back every so often comparing the current return value to that time stamp to get the time since.

3 carry out a code until i hit the reset button

Depending on the code, you can just put that in your loop.

Thank you for your reply. I want the timer to start as soon as the digital pin goes high, and I never want it to look for the status of that pin again. Im thinking i might need another void loop or something but I am not quite sure what the distinct purpose of a void loop is.

3 carry out a code until i hit the reset button

the problem is that i am using a ttl signal that is on for 5ms and off for 2 ms (or something like that) I dont want the code to ever be able to go back into that while loop where the TTL might be low

If you mean until you press the arduino hard reset, then all you need do is wrap your code containing the analogreads and serial prints in a while(true) block.

Yeah I was thinking like a while(1 == 1){code} would do the trick. This may be stupid but could I just write while(true){code}? :stuck_out_tongue_closed_eyes:

While (1) {
  // Code
}

could I just write while(true){code}?

Yes. Or what Arrch suggested.