Hi,
I bought a line sensor digital on sparkfun.com (products_id=9454) and a had some problems to read it.
I tried use pulseIn with timeout, but timeout didn't break pulsein. When sensor get a black floor, pulsein didn't return any value and "void loop()" was freezed waiting for value (or timeout, I don't know).
Now I used the code below:
pinMode( pinLine, OUTPUT );
digitalWrite( pinLine, HIGH );
delayMicroseconds( 50 );
pinMode( pinLine, INPUT );
// long readLine = pulseIn( pinLine, HIGH, 1000000L ); // wait max for 1 second.
long readLine = 0;
while ( digitalRead( pinLine ) == HIGH ) {
pinLine++;
if ( pinLine == 15 ) { break; }
delay( 20 );
}
In my case, 1 = white and 15 = black.
Someone have another idea to solve this?
Thanks.