Serial and Millis

Solved

hook24:
The second problem is when i read in a char, I receive a valos ÿ, for solve it i declare the variable every moment but I think is not the correct way...

Well, the ÿ character has the Ascii value of 255 or -1 for byte values, which, if you bother to read the documentation of the Serial.read() function is the case when you try to read a character but none was there. If you want to read more than one character, check if enough characters are present. if(Serial.available()>0){ only checks if there's more than 0 to be read.

hook24:
the problem is when I use Millis, it's used two times, but the two times asign the same valor to diferent variables.

This happens if the you call millis() more than once inside a millisecond. Then, obviously, the same time should be reported.

Korman

Korman:

hook24:
The second problem is when i read in a char, I receive a valos ÿ, for solve it i declare the variable every moment but I think is not the correct way...

Well, the ÿ character has the Ascii value of 255 or -1 for byte values, which, if you bother to read the documentation of the Serial.read() function is the case when you try to read a character but none was there. If you want to read more than one character, check if enough characters are present. if(Serial.available()>0){ only checks if there's more than 0 to be read.

hook24:
the problem is when I use Millis, it's used two times, but the two times asign the same valor to diferent variables.

This happens if the you call millis() more than once inside a millisecond. Then, obviously, the same time should be reported.

Korman

well u can see the code, when I read I do timeinicial = millis();, later I call the function Controlflujo and I do millis()-timeinicial
it back 0, it's wrong I don't why :S

timeinicial  = millis();
while(!salir){
   if(!ControlFlujo()){

You set the timeinicial to millis() about 8 processor cycles before you try to subtract millis() - timeinicial, which is well under 1 millisecond. Thus, it always returns 0.

hook24:
well u can see the code, when I read I do timeinicial = millis();, later I call the function Controlflujo and I do millis()-timeinicial
it back 0, it's wrong I don't why :S

No, it isn't wrong, it's correct. Whatever you do takes less than 1 millisecond.

Korman