int ldr = A0;
int ldr2 = A1;
double speed,time,distance = 100;//100cm = 1m
double CT = 0;
double LT = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(ldr,INPUT);
pinMode(ldr2,INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(analogRead(ldr)<500){
CT = millis()/1000.0;
}
else if(analogRead(ldr2)<500){
LT = millis()/1000.0;
time = LT - CT;
}
else if(analogRead(ldr)>500 && analogRead(ldr2)>500){
display_speed();
}
}
void display_speed(){
speed = time/distance;
Serial.println(" m/s");
Serial.print(speed);
}