#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <NewPing.h>
#define TRIG_PIN 7
#define ECHO_PIN 6
#define MAX_DISTANCE 400 //JARAK MAKSIMAL YANG DAPAT DIUKUR MENGGUNAKAN MISTAR YANG DIBUAT
LiquidCrystal_I2C lcd(0x27, 16, 2);
NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE);
void setup(){
lcd.begin(16,2);
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Penggaris Auto");
delay(2000);
lcd.clear();
}
void loop(){
int jarak = sonar.ping_cm();
lcd.setCursor(0, 0);
lcd.print("Jarak: ");
if (jarak>0){
lcd.print(jarak);
lcd.print("cm");
}else{
lcd.print("----");
}
delay(500);
}