将测出的距离显示在Around IDE工作区内
时间: 2024-03-11 14:47:36 浏览: 37
好的,你可以按照以下步骤将测出的距离显示在Around IDE工作区内:
1. 首先,在Arduino IDE中打开一个新的Sketch,将以下代码粘贴到代码编辑器中:
```
int trigPin = 13;
int echoPin = 12;
long duration, cm, inches;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
Around.begin("YOUR_APP_ID_HERE", "YOUR_APP_TOKEN_HERE");
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
cm = (duration / 2) / 29.1;
inches = (duration / 2) / 74;
Around.print("Distance: ");
Around.print(cm);
Around.print("cm ");
Around.print(inches);
Around.print("in");
delay(100);
}
```
注意:请将YOUR_APP_ID_HERE和YOUR_APP_TOKEN_HERE替换为你在Around网站上创建的应用的ID和Token。
2. 点击“上传”按钮将代码上传到Arduino UNO开发板。
3. 打开Around IDE工作区,你将看到Arduino UNO开发板测量距离的结果,单位为厘米和英寸。
注意:在使用Around IDE工作区时,请确保已经安装了Around插件,并且已经登录到你的Around账户。如果你还没有Around账户,请在Around网站上注册一个账户。