接了两个超声波,一个有数,一个没有数,两个超声波传感器互换之后,超声波传感器没问题,感觉程序也没问题
const int TrigPin = 4;
const int EchoPin = 5;
int a=11;
int b;
const int T2Pin=2;
const int E2Pin=3;
float distance;
float d2;
boolean ledState = LOW;
void setup() {
Serial.begin(9600);
pinMode(TrigPin, OUTPUT);
pinMode(EchoPin, INPUT);
Serial.println("Ultrasonic sensor:");
pinMode(a,OUTPUT);
Serial.begin(9600);
pinMode(T2Pin, OUTPUT);
pinMode(E2Pin, INPUT);
Serial.println("Ultrasonic sensor:");
pinMode(a,OUTPUT);
}
void loop() {
digitalWrite(TrigPin, LOW);
delayMicroseconds(2);
digitalWrite(TrigPin, HIGH);
delayMicroseconds(10);
digitalWrite(TrigPin, LOW);
digitalWrite(T2Pin, LOW);
delayMicroseconds(2);
digitalWrite(T2Pin, HIGH);
delayMicroseconds(10);
digitalWrite(T2Pin, LOW);
distance = pulseIn(EchoPin, HIGH) / 58.00;
d2 = pulseIn(E2Pin, HIGH) / 58.00;
Serial.print(d2);
Serial.print("cm");
Serial.println();
delay(10);
求大神帮看下,蟹蟹 |