#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
const int pot = A0;
const int buzzPin = 8;
const int servoPin = 9;
const int val;
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo myservo;
void setup() {
Serial.begin(9600);
pinMode(buzzPin,OUTPUT);
myservo.attach(servoPin);
lcd.begin(16, 2);
lcd.init();
lcd.setBacklight(HIGH);
}
void loop() {
int val = analogRead(pot); //membaca sinyal analog input di A0
int sudut = map(val, 0, 1023, 0, 180); //konversi hasil analog (0-1023) menjadi
myservo.write(sudut);
lcd.setCursor(0,0);
lcd.print(" Pot Value : ");
lcd.setCursor(0,1);
Serial.println(val);
if(sudut == 180){
tone(buzzPin,HIGH);
delay(1000);
}
else{
noTone(buzzPin);
}
}