代码:

SR04 + ApmSonar.ino 打包下载

注意,使用到了SR04的类库。

ApmSonar.ino

// sr04 to apm I2c sonar
// by panxu mail: pxzleo@126.com
// Created 2014
#include <Wire.h>
#include "SR04.h"
#define TRIG_PIN 2
#define ECHO_PIN 3
SR04 sr04 = SR04(ECHO_PIN,TRIG_PIN);
uint16_t reading_cm;
uint16_t tempread;
void setup()
{
reading_cm=;
Wire.begin(0x70); // join i2c bus with address #2
Wire.onRequest(requestEvent); // register event
} void loop()
{
tempread=sr04.DistanceAvg(,);
if (tempread<)
reading_cm=tempread;
}
void requestEvent()
{
byte sendhi;
byte sendli;
byte sendbyte[];
uint16_t tempreading_cm;
tempreading_cm=reading_cm;
sendhi=tempreading_cm>>;
sendli=tempreading_cm&0xff;
sendbyte[]=sendhi;
sendbyte[]=sendli;
Wire.write(sendbyte,);
}

最新文章

  1. Struts.xml中Action的method与路径的三种匹配方法
  2. Qt-note0906
  3. HTML5Canvas标签
  4. Encapsulating Data
  5. UvaLive7362 Fare(欧拉函数)
  6. 无线通信技术协议-Zigbee 3.0
  7. Eclipse formater(google Java 编码规范)
  8. Linux下cut命令用法
  9. Zend Studio错误总结
  10. python基础===zip在python3中的用法
  11. FFmpeg的HEVC解码器源代码简单分析:CTU解码(CTU Decode)部分-TU
  12. j2ee应用开发调试工具
  13. BizTalk RosettaNet 开发笔记
  14. 【二次开发】shopxo商城
  15. bzoj 4810 由乃的玉米田 - bitset - 莫队算法
  16. Go 源码学习之--net/http
  17. linux中守护进程启停工具start-stop-daemon
  18. window安装设置
  19. Oracle Data Provider for .NET – Microsoft .NET Core and Entity Framework Core
  20. makefile使用笔记(二)变量

热门文章

  1. iOS 自定义的CodeSnippets添加按下tab键切换到指定输入位置
  2. jenkins和hudson---打酱油的日子
  3. Sass和compass 安装 和配合grunt实时显示 [Sass和compass学习笔记]
  4. 摘要: Linux下which、whereis、locate、find命令的区别
  5. 如何在移动设备上调试html5开发的网页
  6. Oracle ORA-01722: 无效数字 处理方法
  7. finally类
  8. C语言3
  9. 如何使用QQ号进行快捷登录
  10. 基于spring 的单元测试