Hi.
I'm a little stuck with my project and maybe here you can help me here.
What I'm trying to do is reading an LDR sensor, and when it sets HIGH (reads more than 1000) do a 3 sec. delay() and prints "your measure is 1000" (for example) for this three seconds. And then, carry on counting.
The difficult for me is that I have to do it without the delay function, becouse there are foure sensors counting, and if I do a delay(), all of them stop to read.
I have been looking the "blink without delay" function, but I do not understand what is wrong with my code.
I paste here what I have, if some of you want to take a look, I would be very pleased.
Thanks!
sw1.start(); //begins the stopwatch. I'm making an stopwatch for slotcars
/////////////////////////////////////////////
lcd.setCursor(0,0);
lcd.print(sw1.elapsed()); /print stopwatch time
fotoValor1=analogRead(fotoPin1); //LDR reading
int vuelta1; //variable to store if car has pased through sensor
int vuelta1ant=0; //variable to store previous state
if(fotoValor1>1000){ //if reading is > 1000, the car has pased through the sensor, it sets to 1, if not, 0
vuelta1=1;
}
else{
vuelta1=0;
}
Serial.print(vuelta1);
Serial.print(" ");
Serial.println(fotoValor1);
//until here I have it clear, but what I', trying now is:
//when car pass trough the LDR, vuelta1 be =1, stop measuring (to void several measures) and print the time in the screen
if (vuelta1!=vuelta1ant){ //has passed through the LDR
if(vuelta1==1){ //if is passing now
unsigned long valorTiempo1=millis(); //begin the blink without delay
if(millis()-valorTiempo1>3000){
lcd.print(" lap! ");
}
}
vuelta1ant=vuelta1;
}
This is the code I have.
Could someone tell me if see something weird?
I can't get the "delay" nor set the measure to "1" instead "11111111111111111111111" while i'm passing the hand through the sensor.
Thanks!
And sorry about my english, maybe I have misspelt something.