im trying to controll multiple servos with sliders and BLE
here are my code blocks
and here is what the output looks like on the serial monitor
ive tried using a lot of write functions like writeBytes, writeBytesWithResponse, writeIntegers, and much more, but it just gave me diffrent symbols
heres the code from the arduino side
#include <Servo.h>
#define servo1 2
#define servo2 3
#define servo3 4
#define servo4 5
#define servo5 6
Servo Mservo1;
Servo Mservo2;
Servo Mservo3;
Servo Mservo4;
Servo Mservo5;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Mservo1.attach(servo1);
Mservo2.attach(servo2);
Mservo3.attach(servo3);
Mservo4.attach(servo4);
Mservo5.attach(servo5);
Mservo1.write(90);
Mservo2.write(90);
Mservo3.write(90);
Mservo4.write(90);
Mservo5.write(90);
pinMode(servo1, OUTPUT);
pinMode(servo2, OUTPUT);
pinMode(servo3, OUTPUT);
pinMode(servo4, OUTPUT);
pinMode(servo5, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()>0){
String Secondinput = Serial.readStringUntil('\n');
Serial.print( "SecondInput(" );
Serial.print( Secondinput );
Serial.println( ")." );
int RealServo = Secondinput.toInt();
Serial.print("Real Servo = ");
Serial.println(RealServo);
if(RealServo >= 1000 && RealServo <= 1180)
{
int Servo1Input = RealServo;
Servo1Input = map(Servo1Input, 1000, 1180, 0, 180);
Mservo1.write(Servo1Input);
Serial.print("servo 1 = ");
Serial.println(Servo1Input);
}
else if(RealServo >= 2000 && RealServo <= 2180)
{
int Servo2Input = RealServo;
Servo2Input = map(Servo2Input, 2000, 2180, 0, 180);
Mservo2.write(Servo2Input);
Serial.print("servo 2 = ");
Serial.println(Servo2Input);
}
else if(RealServo >= 3000 && RealServo <= 3180)
{
int Servo3Input = RealServo;
Servo3Input = map(Servo3Input, 3000, 3180, 0, 180);
Mservo3.write(Servo3Input);
Serial.print("servo 3 = ");
Serial.println(Servo3Input);
}
else if(RealServo >= 4000 && RealServo <= 4180)
{
int Servo4Input = RealServo;
Servo4Input = map(Servo4Input, 4000, 4180, 0, 180);
Mservo4.write(Servo4Input);
Serial.print("servo 4 = ");
Serial.println(Servo4Input);
}
else if(RealServo >= 5000 && RealServo <= 5180)
{
int Servo5Input = RealServo;
Servo5Input = map(Servo5Input, 5000, 5180, 0, 180);
Mservo5.write(Servo5Input);
Serial.print("servo 5 = ");
Serial.println(Servo5Input);
}
}
}