//deklarasi
#include <ESP32Servo.h>
#define ledbiru 32
#define pushbutton 33
#define alarm 25
Servo myservo;
void setup() {
// put your setup code here, to run once:
pinMode(ledbiru, OUTPUT);
pinMode(pushbutton, INPUT);
pinMode(alarm, OUTPUT);
myservo.attach(18); //pin control
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(pushbutton) == HIGH) { //jika tombol ditekan
digitalWrite(ledbiru, HIGH); //maka lampu biru nyala
tone(alarm, 2000); //alarm nyala
myservo.write(255); //motor nyala
}
else{ //selain kondisi di atas
digitalWrite(ledbiru, LOW); //maka lampu biru mati
noTone(alarm); //alarm mati
myservo.write(0); //motor mati
}
}