当前位置:网站首页>LabVIEW控制Arduino实现超声波测距(进阶篇—5)
LabVIEW控制Arduino实现超声波测距(进阶篇—5)
2022-06-11 21:11:00 【InfoQ】
1、项目概述
2、项目架构

3、硬件环境

4、Arduino功能设计
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
byte comdata[3]={0}; //定义数组数据,存放串口命令数据
int LED = 13; //定义LED连接的管脚
const int TrigPin = 2;
const int EchoPin = 3;
float distance;
void receive_data(void); //接受串口数据
void test_do_data(void); //测试串口数据是否正确,并更新数据
void setup()
{
Serial.begin(9600);
pinMode(LED, OUTPUT);
// Start up the library
sensors.begin();
}
void loop()
{
while (Serial.available() > 0) //不断检测串口是否有数据
{
receive_data(); //接受串口数据
test_do_data(); //测试数据是否正确并更新数据
}
}
void distance_time(void)
{
digitalWrite(TrigPin, LOW);
delayMicroseconds(2);
digitalWrite(TrigPin, HIGH);//发送10μS的高电平触发信号
delayMicroseconds(10);
digitalWrite(TrigPin, LOW);
distance = pulseIn(EchoPin, HIGH); // 检测脉冲宽度,即为超声波往返时间
}
void receive_data(void)
{
int i ;
for(i=0;i<3;i++)
{
comdata[i] =Serial.read();
//延时一会,让串口缓存准备好下一个字节,不延时可能会导致数据丢失,
delay(2);
}
}
void test_do_data(void)
{
if(comdata[0] == 0x55) //0x55和0xAA均为判断是否为有效命令
{
if(comdata[1] == 0xAA)
{
switch (comdata[2])
{
case 0x01:
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.print(sensors.getTempCByIndex(0));
break;
case 0x02:
distance_time();
Serial.print(distance) ;
break ;
}
}
}
}5、LabVIEW功能设计
5.1、前面板设计

5.2、程序框图设计



边栏推荐
- 应用场景:现场直播节目制作NDI技术中PoE网卡的广泛应用
- var 和 let的区别_let 和 var的区别
- Part I physical layer
- JMeter load test finds the maximum number of concurrent users (including step analysis)
- Live broadcast with practice | 30 minutes to build WordPress website with Alibaba cloud container service and container network file system
- Application scenario: wide application of Poe network card in NDI technology for live broadcast program production
- JVM对象分配策略TLAB
- ASCII code comparison table
- Vectordrawable error
- Title does not display after toolbar replaces actionbar
猜你喜欢

第一部分 物理层

Application scenario: wide application of Poe network card in NDI technology for live broadcast program production

JVM object allocation policy TLAB

Add personal statement for go file in file template in Golan

全球机器视觉市场规模持续上涨,PoE图像采集卡为工业相机提供高速传输通道

Windows icon display exception resolution. The desktop icon is abnormal, the start menu icon is abnormal, and the taskbar icon is abnormal. Icon cache location.

Wechat applet | rotation chart

How to manually drag nodes in the Obsidian relationship graph

php pcntl_fork 创建多个子进程解析

One article to show you how to understand the harmonyos application on the shelves
随机推荐
输入值“18-20000hz”错误,设置信息不完整,请选择单位
【博弈论-完全信息静态博弈】 战略式博弈
Explanation of each column output by explain statement
vectorDrawable使用报错
Brain cell membrane equivalent neural network training code
In idea, run the yarn command to show that the file cannot be loaded because running scripts is disabled on this system
Go language conditional statement
RANSAC提取平面(MATLAB内置函数)
RANSAC extraction plane (matlab built-in function)
Lr-link Lianrui makes its debut at the digital Expo with new products - helping the construction of new infrastructure data center
Why should I use iwarp, roce V2, nvme of and other protocols for 100g network transmission
Windows icon display exception resolution. The desktop icon is abnormal, the start menu icon is abnormal, and the taskbar icon is abnormal. Icon cache location.
为什么需要微服务
为什么100G网络传输要使用iWARP、RoCE v2、NVMe-oF等协议
Part II data link layer
New product release: domestic single port Gigabit network card is officially mass produced!
[nk] 牛客练习赛100 C 小红的删数字
BCC tool tool usage
Weekly 02 | to tell you the truth, I am actually a student of MIT
IDEA中,运行yarn命令,显示无法加载文件,因为在此系统上禁用运行脚本