#include <Servo.h>
Servo arm;
float pos = 0.0;
float step = 30.0;
bool increasing = true;
void setup()
{
pinMode(A1, INPUT_PULLUP);
arm.attach(2);
arm.write(pos);
}
void loop()
{
if (!digitalRead(A1))
{
if (increasing)
{
pos += step;
if (pos >= 180)
{
pos = 180;
increasing = false;
}
}
else
{
pos -= step;
if (pos <= 0)
{
pos = 0;
increasing = true;
}
}
arm.write(pos);
delay(300);
}
}