本帖最后由 水镜 于 2015-12-17 22:23 编辑
1602IIC显示+SR04超声波 测量距离
受到温度影响,10度以下,会多出1CM。换个高精度的不知会如何?
Compatible with the Arduino IDE 1.0
Library version1.1
#include Wire.h
#include LiquidCrystal_I2C.h
#include DistanceSRF04.h
LiquidCrystal_I2C lcd(0x27,16,2); set the LCD address to 0x27 for a 16 chars and 2 line display
DistanceSRF04 Dist;
int distance;
void setup()
{
lcd.init(); initialize the lcd
lcd.backlight();
Serial.begin(9600);
Dist.begin(2,3);
}
void loop()
{
distance = Dist.getDistanceCentimeter();
Print a message to the LCD.
lcd.setCursor(0,0);光标从这里开始
lcd.print(Distance is );
lcd.setCursor(0,1);换行后显示距离
lcd.print(distance);
delay(500); make it readable
lcd.clear();
}
用到 LiquidCrystal_I2C.h 和 DistanceSRF04.h这二个库。
SR04 接数字口2、3,1602 IIC 接SCL SDA。
IDE 1.0环境,高版本会出问题。
|