写的一个Arduino控制超声波模块的例子
来源:互联网 发布:身边低调的有钱人知乎 编辑:程序博客网 时间:2024/05/02 04:48
const int TrigPin = 2;
const int EchoPin = 3;
float distance_cm = 0;
void setup() {//这个函数是初始化程序设置
// put your setup code here, to run once:
Serial.begin(9600);//设置串口波特率
pinMode(TrigPin,OUTPUT);//设置针脚数字端口,为输入,输出,
pinMode(EchoPin,INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(TrigPin,LOW);
delayMicroseconds(2);
digitalWrite(TrigPin,HIGH);
delayMicroseconds(10);
digitalWrite(TrigPin,LOW);//设置引脚的输出电压为高电平或者低电平
distance_cm = pulseIn(EchoPin,HIGH)/58.0;//算成厘米
distance_cm = (int(distance_cm * 100.0))/100.0;//保留两位小数
Serial.print(distance_cm);
Serial.print("cm");
Serial.println();
delay(1000);
}
0 0
- 写的一个Arduino控制超声波模块的例子
- 【Arduino】超声波模块(HC-SR04)
- arduino 超声波 HC-SR04模块
- 超声波模块的51程序
- Arduino 2.4G通信实验 nRF24L01模块的简单例子
- arduino的超声波测距和pulseIn()函数的使用说明
- 51单片机之超声波模块的使用
- 自己写的一个例子
- 基于Arduino实现Arduino控制的电灯
- 控制Arduino的利器-Windows Remote Arduino
- 控制Arduino的利器-Windows Remote Arduino
- 写一个模块的步骤:
- 基于Dragon Board410c与科大讯飞麦克风阵列模块的语音唤醒控制以及US-100超声波的实际应用
- Arduino 小玩意之 HC-SR04 超声波测距模块
- STM32控制超声波测距模块HC-SR04
- Arduino对舵机的控制
- python types模块MethodType的一个例子
- 写的委托的一个简单例子
- Android并发编程之图文解析volatile关键字
- ConstraintLayout使用浅谈
- leetcode 93. Restore IP Addresses
- Android Dialog总结
- QT学习链接
- 写的一个Arduino控制超声波模块的例子
- javascriptAPI-高德地图(点击选地址)
- C#枚举类型的常用操作总结
- 判断某个窗口是否是活动窗口(当前正在使用、操作的窗口)
- iOS开发:整理UITextField属性的基本用法(部分)
- tcp socket文件句柄泄漏
- 交换瓶子
- 全志R16调通USB接口的WIFI:RTL8188CUv1.0版本.txt
- boost 时间与日期处理