// include the library code:
#include <LiquidCrystal.h>
#include <Servo.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
int val;
const int ECHO_PIN = 6;
const int TRIG_PIN = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
Servo myServo;
Servo myServoTwo;
Servo myServoThree;
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
pinMode(13, INPUT_PULLUP);
// set up the LCD's number of columns and rows:
lcd.begin(10, 2);
// Print a message to the LCD.
lcd.print("hello guys! How are you");
myServo.attach(1);
myServoTwo.attach(10);
myServoThree.attach(13);
}
void loop() {
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
int duration = pulseIn(ECHO_PIN, HIGH);
float distance = duration * 0.034 / 2;
Serial.print("Jarak: ");
Serial.println(distance);
delay(100);
//myServo.write(0);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
if (13 == HIGH) {
myServo.write(180);
myServoTwo.write(180);
myServoThree.write(180);
} else {
myServo.write(0);
myServoTwo.write(0);
myServoThree.write(0);
}
}