Hello!
I'm trying to use the pulseIn() function to read from a parallax ping() sensor. It reads the pulse length from the sensor great, but the optional timeout part of it is not working.
My ping outputs a pulse length of about 9000 when I point it at empty space. I'd like to set pulseIn to give up at around 2600, which would give me a speed boost because I wouldn't have to wait the extra 6.4mS for the ping to time out.
Here is the test code:
long pulselength = 0;
//float inches = 0;
int pulsepin = 2;
void setup() {
Serial.begin(57600);
} //end setup()
void loop() {
pinMode(pulsepin, OUTPUT);
digitalWrite(pulsepin, LOW);
delayMicroseconds(2);
digitalWrite(pulsepin, HIGH);
delayMicroseconds(5);
digitalWrite(pulsepin, LOW);
pinMode(pulsepin, INPUT);
pulselength = pulseIn(pulsepin, HIGH, 2600);
Serial.println(pulselength);
} //end loop
Note: even if you don't have a ping, you can load this up and verify that it is returning higher numbers than 9000, instead of the expected 0.