Go Down

Topic: problem with time limiting code using millis() (Read 410 times) previous topic - next topic

vitesse

I have found  some information about using millis() for time limiting application on the forum, so I tried to use it.  but it doesn't work, giving me this error:

error: stray '\' in program In function 'void RotatorLeft()':

here my small portion code that I use to do it:

Code: [Select]
void RotatorLeft()  // LEFT = HIGH
{    
unsigned long StartTime = millis();
while (RotatorLevel <= (RequestDegree) -3 && StopRotation !=1 && millis() - StartTime < 90000 && RotatorLevel < 360) { digitalWrite(LEFT_OUT, HIGH); digitalWrite(POWER_OUT, HIGH); ReadRotator(); SerialRotatorSend();}
       digitalWrite(POWER_OUT, LOW);
       digitalWrite(LEFT_OUT, LOW); RequestDegree=0;  
       StopRotation = 1;
}


So my goal is that the script stop working after 90 sec, so not to blow the motor, as it should never take so long and probably something wrong happening.

Fjornir

Did you edit this code in a word processor or 'smart' editor of some sort that might replace a normal ascii minus sign with some sort of unicode dash? Copy it from a webpage that might have done that? The character in your millis() - StartTime  looks like a minus sign but it is something else. Delete it and type the minus sign and try to recompile.


vitesse

Big thanks for the help. this was exactly the problem.

This was a cut/past from my web browser.

This will be a great information for my future code as I often cut/past existing part of code.

Go Up