Hi,
I want to measure the time one of the digital input pins is high (or low). I'm doing the following:
estat=digitalRead(4);
do {} while(digitalRead(4)==estat); // wait until changes
t1=millis(); // measure the change
do {} while(digitalRead(4)==!estat);
t2=millis();
t=t2-t1;
Serial.println(t);
My questions are:
1-How accurate you think that is? The time for calling millis() and the digital read eat time, so..
2-How can I do it for intervals below 1ms?
What if the pulse already began when you call the function?
ie, the pin is already high and you want to know how long does it take to go low.
It seems this is not supported, where can I find the library code to change it ?