#include <Servo.h>
Servo servo; // Create a "Servo" object called "servo"
float pos = 0.0; // Variable where the servo's position will be stored (in degrees)
float step = 1.0; // Variable used for the servo's position step
void setup()
{
Serial.begin(9600);
pinMode(A1, INPUT_PULLUP); // Set the A1 pin to a pushbutton in pullup mode
pinMode(A2, INPUT_PULLUP); // Set the A1 pin to a pushbutton in pullup mode
servo.attach(2); // Attache the servo to the pin 2
servo.write(pos); // Initialize the servo's position to 0 (leftmost)
}
void loop()
{
Serial.println(servo.read());
if (!digitalRead(A1)==HIGH)
{
//buka servo
if(servo.read()== 0){
openLid();
}else if(servo.read()== 90){
closeLid();
//tutup servo
}
}
}
void openLid(){
servo.write(90);
}
void closeLid(){
servo.write(0);
}