DIY PIXHAWK APM等飞控用的声纳
2024-08-25 00:17:16
代码:
注意,使用到了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,);
}
最新文章
- Struts.xml中Action的method与路径的三种匹配方法
- Qt-note0906
- HTML5Canvas标签
- Encapsulating Data
- UvaLive7362 Fare(欧拉函数)
- 无线通信技术协议-Zigbee 3.0
- Eclipse formater(google Java 编码规范)
- Linux下cut命令用法
- Zend Studio错误总结
- python基础===zip在python3中的用法
- FFmpeg的HEVC解码器源代码简单分析:CTU解码(CTU Decode)部分-TU
- j2ee应用开发调试工具
- BizTalk RosettaNet 开发笔记
- 【二次开发】shopxo商城
- bzoj 4810 由乃的玉米田 - bitset - 莫队算法
- Go 源码学习之--net/http
- linux中守护进程启停工具start-stop-daemon
- window安装设置
- Oracle Data Provider for .NET – Microsoft .NET Core and Entity Framework Core
- makefile使用笔记(二)变量