Hello,
I am trying to create a program so that I can move a servomotor at a specific angle and after a delay, it turns back to its initial position.
Theoretically, if I write move the servo motor should move 60º and then come back (-60º)
This is what I have but I don't know why it is not working
#include <Servo.h>
Servo servo1;
int i = 0;
String command;
void setup() {
Serial.begin(9600);
servo1.attach(2);
}
void loop() {
if(Serial.available()){
command = Serial.readStringUntil('\n');
if(command.equals("move")){
for (i = 0; i < 60; i++) {
servo1.write(i);
delay(10);
}
for (i = 59; i > 0; i--) {
servo1.write(i);
delay(10);
}
command = 'o';
}
}
}