#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Task-2 ⬇️
int time = 0;
int distance = 0;
int echo = 11;
int trigger = 12;
// Task-2 ⬆️
void setup() {
// put your setup code here, to run once:
// Task-2 ⬇️
pinMode(echo, INPUT);
pinMode(trigger, OUTPUT);
// Task-2 ⬆️
lcd.init();
lcd.backlight();
Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Hello, World");
delay(2000);
}
void loop() {
// put your main code here, to run repeatedly:
// Task-2 ⬇️
lcd.clear();
digitalWrite(trigger, LOW);
digitalWrite(trigger, HIGH);
time = pulseIn(echo, HIGH);
distance = 0.0172 * time;
lcd.setCursor(5,0);
lcd.print(distance);
lcd.print("cm");
delay(1000);
// Task-2 ⬆️
}