const int TrigPin = 7;
const int EchoPin = 10;
float distance;
int S= 7;
int qqq;
int bbb;
void setup() {
Serial.begin(9600);
pinMode(TrigPin, OUTPUT);
pinMode(EchoPin, INPUT);
pinMode(S, INPUT);
}
void loop() {
{ int Se = digitalRead(S);
Serial.println(Se); }
{digitalWrite(TrigPin, LOW);
delayMicroseconds(2);
digitalWrite(TrigPin, HIGH);
delayMicroseconds(10);
digitalWrite(TrigPin, LOW);
distance = pulseIn(EchoPin, HIGH) / 58.00;
Serial.print(distance);
Serial.print("cm");
Serial.println();
bbb=distance;
Serial.write(bbb);
}
}
有时有用 ........ 有时没用.......?????
人体红外感应 =1 距离传感器 有反映(第2次)
1
0
1
184MM
---------------------------------------------------------------------------
const int TrigPin = 7; 换成10
const int EchoPin = 10; 换成 7
距离传感器没用......
人体有用
------------------------------------------------------------------------------
void loop() {
qqq=Serial.read();
if(qqq=='e')
{digitalWrite(TrigPin, LOW);
delayMicroseconds(2);
digitalWrite(TrigPin, HIGH);
delayMicroseconds(10);
digitalWrite(TrigPin, LOW);
distance = pulseIn(EchoPin, HIGH) / 58.00;
Serial.print(distance);
Serial.print("cm");
Serial.println();
bbb=distance;
Serial.write(bbb);
}
if(qqq=='a')
{ int Se = digitalRead(S);
Serial.println(Se); }
}
距离没用
人体可以
????????????
高手指点一下吧 谢谢
|