对了,成功后尝试使用超声波传感器控制灯,结果没有得到测试数据
- float checkdistance_20_21() {
- digitalWrite(20, LOW);
- delayMicroseconds(2);
- digitalWrite(20, HIGH);
- delayMicroseconds(10);
- digitalWrite(20, LOW);
- float distance = pulseIn(21, HIGH) / 58.00;
- delay(10);
- return distance;
- }
-
- void setup(){
- pinMode(20, OUTPUT);
- pinMode(21, INPUT);
- Serial.begin(9600);
- }
-
- void loop(){
- Serial.println(checkdistance_20_21());
-
- }
复制代码
|