Hey guys i am using the millis() functiuon to create a timestamp, then keep track of time using "time = millis - timestamp" logic. Here is my code:
void loop(){
Serial.println("#S|CPBLTST|[]#");
Serial.println("#S|THRMLOG|[Time(ms);Vin0;Vin1;Vin2;Vin3;Vin4;Vin5;Vin6;Vin7;Vin8]#");
** tStart = millis();**
while(true){
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[10];
Serial.print("#S|THRMLOG|[");
tTest = millis() - 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.println("]#");
delay(1000);
}
}
Here are the consecutive readouts approximately where things start to go wrong:
30255;901;898;903;901;902;
31257;901;898;903;902;902;
32258;901;898;903;903;902;
-32276;901;897;903;903;903;
-31274;902;898;903;901;902;
-30273;901;898;903;902;902;
It will loop all the way back to 31258 then go to -32276. Anyone know the reason this may be happening?
EDIT: I solved this by declaring tTest as a long rather than int. However, that is not the only thing I had to do, I also had to eliminate the itoa function, and I got lucky because for some reasonb gobetwino doesnt require the number to be converted to a string, although it says to in the user manual.