サンプルスケッチ
include <VarSpeedServo.h>
VarSpeedServo myservo; // create servo object to control a servo
int x = 0;
int y = 0;
int movestatus = 0; //if approaching 1,leaving -1
void setup() {
Serial.begin(9600);
myservo.attach(6); // attaches the servo on pin 9 to the servo object
pinMode(10,OUTPUT);
digitalWrite(10, HIGH);
}
void loop() {
digitalWrite(10, HIGH);
x = digitalRead(2);
y = digitalRead(7);
y = y-2;
if (x==1 && y!=-1){
if(movestatus == -1 || movestatus == 0){
myservo.write(30, 3000, false);
movestatus = 1;
}
}
else if (x != 1 && y == -1){
if(movestatus == 1 || movestatus == 0){
myservo.write(180, 3000, false);
movestatus = -1;
}
}