#include <Servo.h>
// Define the servo pins
int servo1Pin = 9;
int servo2Pin = 10;
int servo3Pin = 11;
// Define the servo objects
Servo servo1;
Servo servo2;
Servo servo3;
// Define the angles of each servo motor in the default position (90 degrees)
int theta1_0 = 90;
int theta2_0 = 90;
int theta3_0 = 90;
void setup() {
// Initialize the serial communication
Serial.begin(9600);
// Attach the servo objects to the pins
servo1.attach(servo1Pin);
servo2.attach(servo2Pin);
servo3.attach(servo3Pin);
// Move the servos to the default position
servo1.write(theta1_0);
servo2.write(theta2_0);
servo3.write(theta3_0);
// Wait for the servos to reach the default position
delay(1000);
}
void loop() {
// Read the incoming data from the serial communication
if (Serial.available() > 0) {
String data = Serial.readStringUntil('\n');
data.trim();
// Split the data into three parts separated by commas
int commaIndex1 = data.indexOf(',');
int commaIndex2 = data.indexOf(',', commaIndex1+1);
String theta1String = data.substring(0, commaIndex1);
String theta2String = data.substring(commaIndex1+1, commaIndex2);
String theta3String = data.substring(commaIndex2+1);
// Convert the strings to integers
int theta1 = theta1String.toInt();
int theta2 = theta2String.toInt();
int theta3 = theta3String.toInt();
// Move the servos to the specified angles
servo1.write(theta1);
servo2.write(theta2);
servo3.write(theta3);
// Wait for the servos to reach the specified angles
delay(1000);
}
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
servo1:GND
servo1:V+
servo1:PWM
servo2:GND
servo2:V+
servo2:PWM
servo3:GND
servo3:V+
servo3:PWM