当前位置:网站首页>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、程序框图设计



边栏推荐
- Network security Kali penetration learning introduction to web penetration using MSF penetration to attack win7 host and execute commands remotely
- Release of version 5.6 of rainbow, add multiple installation methods, and optimize the topology operation experience
- JVM之堆区
- [Game Theory - introduction]
- JVM object allocation policy TLAB
- One article to show you how to understand the harmonyos application on the shelves
- Pyqt5 technical part - set the default value of qcombobox drop-down box and get the current selection of the drop-down box
- The official announced the launch of Alibaba's 2023 global school recruitment: Technical Posts account for more than 60%
- var 和 let的区别_let 和 var的区别
- Capriccio in the Internet Age
猜你喜欢

IDEA中,运行yarn命令,显示无法加载文件,因为在此系统上禁用运行脚本
![[game theory complete information static game] strategic game](/img/d2/743e8d14e4fb27cbe883d1df1bca27.jpg)
[game theory complete information static game] strategic game

Tensorflow 2. X Getting Started tutorial

The scale of the global machine vision market continues to rise. Poe image acquisition card provides a high-speed transmission channel for industrial cameras

Modify appid of local wechat applet

第一部分 物理层

Live broadcast with practice | 30 minutes to build WordPress website with Alibaba cloud container service and container network file system

PHP strtotime 获取自然月误差问题解决方案
![[nk] deleted number of 100 C Xiaohong in Niuke practice match](/img/f1/a99600e1800c087aceb60a559dee39.png)
[nk] deleted number of 100 C Xiaohong in Niuke practice match

JVM method area
随机推荐
LR-LINK联瑞携新品首次亮相数博会-助力新基建数据中心建设
Online excel file parsing and conversion to JSON format
Add personal statement for go file in file template in Golan
gateway先启动其他微服务,在启动网关,网关启动不了,且无异常日志;先启动网关,所有服务能正常启动
Go语言条件语句
Wechat applet Bluetooth development
周刊02|不瞒你说,我其实是MIT的学生
Which Bluetooth headset is better within 500? Inventory of gifts for girls' Day
Deploy website traffic statistics background based on Tencent cloud lightweight application server and umami
A man always becomes a man and a man always arrives (progress, harvest, growth, self-confidence)
全球机器视觉市场规模持续上涨,PoE图像采集卡为工业相机提供高速传输通道
Application analysis of Poe image acquisition card in machine vision industrial computer
Online excel file parsing and conversion to JSON format
Field queryIndexFieldnameService in xxxImpl required a single bean, but 19 were found:
Solution to the problem of PHP strtotime obtaining natural monthly error
应用业务层修改
Bug -- coredump usage
Weekly 02 | to tell you the truth, I am actually a student of MIT
Cs144 lab0 lab1 record
JVM方法区