2016-04-14 09:00:08 +02:00
|
|
|
#include <NewPing.h>
|
|
|
|
#include <Wire.h>
|
|
|
|
#include <LiquidCrystal_I2C.h>
|
|
|
|
|
|
|
|
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
|
2016-04-14 09:19:47 +02:00
|
|
|
NewPing sonar(12,11);
|
2016-04-14 09:00:08 +02:00
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
lcd.begin(16,2);
|
|
|
|
|
|
|
|
for(int i = 0; i< 3; i++)
|
|
|
|
{
|
|
|
|
lcd.backlight();
|
|
|
|
delay(250);
|
|
|
|
lcd.noBacklight();
|
|
|
|
delay(250);
|
|
|
|
}
|
|
|
|
|
|
|
|
lcd.backlight();
|
|
|
|
|
|
|
|
lcd.setCursor(0,0);
|
|
|
|
lcd.print("Distance in cm");
|
|
|
|
}
|
|
|
|
|
2016-04-14 09:45:55 +02:00
|
|
|
char cm[3];
|
2016-04-14 09:32:36 +02:00
|
|
|
|
2016-04-14 09:00:08 +02:00
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
lcd.setCursor(0,1);
|
2016-04-14 09:32:36 +02:00
|
|
|
sprintf(cm, "%.3i", sonar.ping_cm());
|
|
|
|
lcd.print(cm);
|
2016-04-14 09:00:08 +02:00
|
|
|
delay(50);
|
|
|
|
}
|