i want to controll three serve motors simultaneously, and the problem i faced was the the servo was not stopped at the angle i want, but continuously rotating round
(this is the app inventor image)
#include <Servo.h>
#include <SoftwareSerial.h>
Servo servo1;
Servo servo2;
Servo servo3;
SoftwareSerial HC06(2, 3);
void setup() {
servo1.attach(5); // 서보 모터 1 연결 핀
servo2.attach(6); // 서보 모터 2 연결 핀
servo3.attach(9); // 서보 모터 3 연결 핀
HC06.begin(9600);
Serial.begin(9600);
}
void loop() {
if (bluetooth.available()) {
String command = bluetooth.readStringUntil('\n'); //문자열이 끝날때까지 해당 string의 값을 읽음.
Serial.println(command); //아두이노의 시리얼 모니터에 어떤 문자열의 값이 나타내져있는지를 나타냄.
if (command.startsWith("S1:")) {
int angle = command.substring(3).toInt(); // 3번째 문자열 이후부터의 숫자를 인식하여 해당 servo1의 값에 저장
servo1.write(angle);
} else if (command.startsWith("S2:")) {
int angle = command.substring(3).toInt();
servo2.write(angle); // 3번째 문자열 이후부터의 숫자를 인식하여 해당 servo2의 값에 저장
} else if (command.startsWith("S3:")) {
int angle = command.substring(3).toInt();
servo3.write(angle); // 3번째 문자열 이후부터의 숫자를 인식하여 해당 servo2의 값에 저장
}
}
and this is the code i wrote
How can i fix this code to stop at the specific angle i want?