水镜 发表于 2015-12-17 22:16:29

1602IIC显示+SR04超声波 测量距离

本帖最后由 水镜 于 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环境,高版本会出问题。

PINKWALKMAN 发表于 2015-12-18 07:55:13

声速随温度有变化。

水镜 发表于 2015-12-18 10:06:33

做个加温试验,看看变化过程,哈哈。
页: [1]
查看完整版本: 1602IIC显示+SR04超声波 测量距离