So the idea is to create a system that can detect either directions first so I could tell where the vehicle is coming from (i.e which direction), the speed, and vehicles/min. But back to the original question, would the code below effectively work in my scenario.
void loop() {
lcd.setCursor(0,0);
analogVal = analogRead(analogPin);
delay(10);
digitalVal = digitalRead(digitalPin);
delay(10);
if (analogVal <= 400 || analogVal >= 600) {
t0 = micros();
String message1 = "Analog Detected";
Serial.println(message1);
timeout0 = millis(); //timestamp for delay
if ((millis() - timeout0) > 400){ // wait 400ms until Analog Pin is LOW
newAnalog = analogRead(analogPin); // check to see motion is done
newAnalogVal = newAnalog + 500; // absolute value idea
if (newAnalogVal < 600){ //check case to see if analogRead is below 600
}
}
computeData_0();
}
else if (digitalVal == HIGH) {
String message2 = "Digital Detected";
Serial.println(message2);
t1 = micros(); //timestamp for calulating speed, concentration
timeout1 = millis(); //timestamp for delay
if ((millis() - timeout1) > 400){ // wait 400ms until Digital Pin is LOW
newDigital = digitalRead(digitalPin); // Check to see that digital sensor is done detecting
if (newDigital == LOW){ // Once LOW, compute our data
}
}
computeData_1();
}
So my if ((millis() - timeout1) > 400){ should keep taking a timestamp until its greater than 400ms then sample the analogRead/digitalRead pins to see if the sensor is still HIGH or in the analog case over the the threshold voltage. Once LOW or below my threshold, I go into my computeData() function which computes a bunch of data.
Is this correct in my thinking? Will the above code do this?