//Nama : Husein Yudha
//Nim: 220204010
//Kelas: TL 2A
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo servo1;
Servo servo2;
#define masuk 3;
#define keluar 4;
#define servo_in 5;
#define servo_out 6;
int ECHO_MASUK=8;
int TRIG_MASUK=9;
int ECHO_KELUAR=10;
int TRIG_KELUAR=11;
int jumlah_mobil = 0;
int slot_mobil = 5;
int jumlah_mobil_max = 5;
void setup() {
// put your setup code here, to run once:
pinMode(8, INPUT);
pinMode(9, OUTPUT);
pinMode(10, INPUT);
pinMode(11, OUTPUT);
Serial.begin(9600);
servo1.attach(5);
servo2.attach(6);
lcd.begin(16,2);
lcd.init();
lcd.backlight();
servo1.write(0);
servo2.write(0);
lcd.setCursor(2,0);
Serial.println("SISTEM PARKIR");
lcd.setCursor(4,1);
Serial.println("OTOMATIS");
delay(3000);
pinMode(5, INPUT);
pinMode(6, INPUT);
lcd.clear();
lcd.print("SLOT PARKIR :");
lcd.print(slot_mobil);
}
void loop()
{
// put your main code here, to run repeatedly:
digitalWrite(9,HIGH);
delayMicroseconds(10);
digitalWrite(9,LOW);
double selang1=pulseIn(8,HIGH);
double jarak1=0.0343*(selang1/2);
digitalWrite(11,HIGH);
delayMicroseconds(10);
digitalWrite(11,LOW);
double selang2=pulseIn(10,HIGH);
double jarak2=0.0343*(selang2/2);
int in_value(jarak1>10||jarak1<=0);
int out_value(jarak2>10||jarak2<=0);
if(in_value == LOW &&jumlah_mobil < jumlah_mobil_max)
{
jumlah_mobil ++;
slot_mobil --;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("PARKIR TERSEDIA");
lcd.setCursor(0,1);
lcd.print(slot_mobil);
servo1.write(90);
delay(3000);
servo1.write(0);
delay(1000);
}
if (out_value == LOW && jumlah_mobil> 0 )
{
jumlah_mobil--;
slot_mobil++;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Slot Parkir:");
lcd.setCursor(0,1);
lcd.print(slot_mobil);
servo2.write(90);
delay(3000);
servo2.write(0);
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Parkir Tersedia");
delay(1000);
}
if(jumlah_mobil == jumlah_mobil_max)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("PARKIR PENUH");
delay(1000);
}
}