该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
如下是例程,但是,按照程序的指示,似乎是直接连接单片机的A4A5接口,然而,电压范围不同,会不会有问题,建议在拿不准的情况下,加上电压转换装置。
***************************************************************
Arduino GP2Y0E03 example code
Gets range from GP2Y0E03 and prints it to the serial monitor.
Pin Connect:
GP2Y0E03 Arduino
1.PIN--VCC 3V3
2.PIN--Vout(A) Not Connect
3.PIN--GND GND
4.PIN--VIN(IO) 3V3
5.PIN--GPIO1 3V3
6.PIN--SCL A5
7.PIN--SDA A4
***************************************************************/
#include
int distance = 0; // Stores the calculated distance
byte high, low = 0; // High and low byte of distance
int shift = 0; // Value in shift bit register
#define ADDRESS 0x80 >> 1 // Arduino uses 7 bit addressing so we shift address right one bi