#include <Servo.h>
int buttonpin = 7;
int last_state = HIGH;
int relaypin = 8;
Servo myservo;
int pos = 0;
void setup() {
Serial.begin(115200);
pinMode(buttonpin,INPUT_PULLUP);
pinMode(relaypin,OUTPUT);
myservo.attach(9);
}
void loop() {
int value = digitalRead(buttonpin);
if(last_state != value ){
last_state = value;
if(value == HIGH){
digitalWrite(relaypin,LOW);
Serial.println("released");
for(pos = 0;pos <=180; pos +=1 ){
myservo.write(pos);
delay(15);
}
}
else{
digitalWrite(relaypin,HIGH);
Serial.println("pressed");
}
}
}