#include <Servo.h>
Servo arm; // Create a "Servo" object called "arm"
float pos = 0.0; // Variable where the arm's position will be stored (in degrees)
float step = 1.0; // Variable used for the arm's position step
int lvl = 0;
#define LED 6
#define SERV 2
void setup() {
// put your setup code here, to run once:
pinMode(LED, OUTPUT);
pinMode(A1, INPUT_PULLUP);
arm.attach(SERV);
arm.write(pos);
}
void loop() {
// put your main code here, to run repeatedly:
lvl = digitalRead(A1) ? LOW : HIGH;
digitalWrite(LED, lvl);
if (!digitalRead(A1)) {
if (pos < 1) step = 1.0;
if (pos > 179) step = -1.0;
pos += step;
arm.write(pos);
delay(5);
}
}