//#include <ESP32Servo.h>
#include <Servo.h>
const int servoPin = 13;
const int mag_switch = 12;
Servo servo;
void setup() {
servo.attach(servoPin, 500, 2400);
Serial.begin(115200);
Serial.print("start");
pinMode(12, INPUT_PULLUP);
}
int pos = 0;
int var = 0;
bool a;
void loop() {
a = digitalRead(mag_switch);
switch (var) {
case 0: {
if (a == LOW) {
delay(15);
var = 1;
pos = 0;
Serial.println("s0");
}
}
break;
case 1 :{
for (pos = 0; pos <= 180; pos += 1) {
servo.write(pos);
delay(15);
}
if (pos == 181) {
Serial.println("s1");
var=2;
}
}
break;
case 2:{
if(a==HIGH){
for (pos = 182; pos >= 1; pos -= 1) {
servo.write(pos);
delay(15);
}
if(pos==0){
var=0;
}
}
}
break;
default :{var=0;}
}
}