#include <Servo.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2

LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
#define LED_BUILTIN 4
#define LED_ON digitalWrite(LED_BUILTIN, HIGH)
#define LED_OFF digitalWrite(LED_BUILTIN, LOW)
#define KAKI_POTENSIO A0

Servo myservo;
int pos = 0;
void setup() {
  // put your setup code here, to run once:
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);
  Serial.println("PROGRAM MUHAMMAD ARJUNA ANGGARA PUTRA DIJALANKAN.....");

  myservo.attach(6);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.println("-----17-----");
  lcd.setCursor(0,1);
  lcd.println("M ARJUNA AP");
  delay(5000);
  lcd.setCursor(0,1);
  lcd.println("         ");

}
uint16_t data;
uint16_t pot_pos;
uint16_t servo_pos;
void loop() {
  // put your main code here, to run repeatedly:
  data = analogRead(KAKI_POTENSIO);
  servo_pos = map(data, 0, 1023, 0, 180);
  pot_pos = map(data, 0, 1023, 0, 90);
  Serial.println("raw[" + String(data)+ "] ,degree["+String(pot_pos)+"], servo["+String(servo_pos)+"]");
  if (pot_pos >= 45)
  {
    LED_OFF;
    lcd.setCursor(0,0);
    lcd.println("LED OFF BOS");
  }
  if (pot_pos < 45)
  {
    LED_ON;
    lcd.setCursor(0,0);
    lcd.println("LED ON BOS");
  }
  myservo.write(servo_pos);
  lcd.setCursor(0,1);
  lcd.println("POSISI :");
  lcd.setCursor(8,1);
  lcd.println(servo_pos);
}