I've got proximity sensors connected to pins 10 and 11. I'm using digitalWrite and digitalRead as below but pin 10 always reads zero. It doesn't matter whether I run the program with pin 10 or 11 first. Both pins operate as expected when only one pin is manipulated (set both _pin to 10 or 11). I see many posts in the forum using multiple pins but nothing that clues me in. Here's the code.
void setup()
{
Serial.begin(9600);
}
void loop()
{
long duration;
int _pin;
_pin = 11;
pinMode(_pin, OUTPUT);
digitalWrite(_pin, LOW);
delayMicroseconds(2);
digitalWrite(_pin, HIGH);
delayMicroseconds(5);
digitalWrite(_pin,LOW);
pinMode(_pin,INPUT);
duration = pulseIn(_pin,HIGH);
duration = duration/74/2;
Serial.print("Pin ");
Serial.print (_pin);
Serial.print (": The distance to obstacles in front is: ");
Serial.print(duration);
Serial.println(" inch ");
delay(500);
_pin = 10;
pinMode(_pin, OUTPUT);
digitalWrite(_pin, LOW);
delayMicroseconds(2);
digitalWrite(_pin, HIGH);
delayMicroseconds(5);
digitalWrite(_pin,LOW);
pinMode(_pin,INPUT);
duration = pulseIn(_pin,HIGH);
duration = duration/74/2;
Serial.print("Pin ");
Serial.print (_pin);
Serial.print (": The distance to obstacles in front is: ");
Serial.print(duration);
Serial.println(" inch ");
delay(500);
}