我是靠谱客的博主 风中大山,最近开发中收集的这篇文章主要介绍arduino与hcsr04_超声波测距(HC-SR04)+arduino制作倒车雷达,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

#include

#define TRIGGER_PIN    12

#define ECHO_PIN       13

#define NUMBER_BUFFERS 3

#define BUFFER_SIZE    3

#define BUFFER_01      0

#define BUFFER_02      1

#define BUFFER_03      2

Ultrasonic ultrasonic(TRIGGER_PIN, ECHO_PIN);

bool disableSD = false;

size_t count = 0;

void setup()

{

Serial.begin(9600);

Serial.println("Starting Ultasonic Test using standard deviation ...");

pinMode(3,OUTPUT);

pinMode(4,INPUT);

/*

* If NUMBER_BUFFERS is 2 then it must be followed by two size variables

* one for each buffer to be created. The size variables do not need to be

* the same value.

*

* Example: ultrasonic.sampleCreate(3, 20, 10, 3) is valid.

*

* Note: The minimum size for any buffer is 2. Using less than 2 will waist

*       resources and the buffer will be ignored.

*/

if(!ultrasonic.sampleCreate(NUMBER_BUFFERS, BUFFER_SIZE, BUFFER_SIZE,

BUFFER_SIZE))

{

disableSD = true;

Serial.println("Could not allocate memory.");

}

}

void loop()

{

float cmMsec, inMsec;

float msStdDev, cmStdDev, inStdDev;

long microsec = ultrasonic.timing();

cmMsec = ultrasonic.convert(microsec, Ultrasonic::CM);

inMsec = ultrasonic.convert(microsec, Ultrasonic::IN);

if(disableSD)

{

Serial.print("CM: ");

Serial.print(cmMsec);

Serial.print(", IN: ");

Serial.println(inMsec);

}

else

{

msStdDev = ultrasonic.unbiasedStdDev((float) microsec, BUFFER_01);

cmStdDev = ultrasonic.unbiasedStdDev(cmMsec, BUFFER_02);

inStdDev = ultrasonic.unbiasedStdDev(inMsec, BUFFER_03);

Serial.print(", CM: ");

Serial.print(cmMsec);

}

if(cmMsec<=200)

{

Serial.println("in if") ;

digitalWrite(3,HIGH);

delay(cmMsec*3);

digitalWrite(3,LOW);

tone(4,1000);

delay(cmMsec*6);

noTone(4);

}

delay(100);

}

最后

以上就是风中大山为你收集整理的arduino与hcsr04_超声波测距(HC-SR04)+arduino制作倒车雷达的全部内容,希望文章能够帮你解决arduino与hcsr04_超声波测距(HC-SR04)+arduino制作倒车雷达所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(77)

评论列表共有 0 条评论

立即
投稿
返回
顶部