#include #include Servo Servo_Rack_Pinion; Servo Servo_Yaw; Servo Servo_Pitch; // Define GPIO pin for the servo #define SERVO_RP_PIN 3 #define SERVO_YAW_PIN 4 #define SERVO_PITCH_PIN 5 String lastData = ""; // Initialize with an empty string void setup() { Serial.begin(9600); // Initialize serial communication at 9600 baud rate Servo_Rack_Pinion.attach(SERVO_RP_PIN); Servo_Yaw.attach(SERVO_YAW_PIN); Servo_Pitch.attach(SERVO_PITCH_PIN); } void loop() { if (Serial.available() > 0) { String inputString = Serial.readStringUntil('\n'); // Read the entire string until newline if (inputString != lastData) { // It's a new packet of information lastData = inputString; // Update the last data packet // Variables to store the split values int yaw, pitch, fire; // Find the positions of the commas int firstCommaIndex = inputString.indexOf(','); int secondCommaIndex = inputString.indexOf(',', firstCommaIndex + 1); // Split the string and convert to integers yaw = inputString.substring(0, firstCommaIndex).toInt(); pitch = inputString.substring(firstCommaIndex + 1, secondCommaIndex).toInt(); fire = inputString.substring(secondCommaIndex + 1).toInt(); Serial.print("yaw is: "); Serial.println(yaw); Serial.print("pitch is: "); Serial.println(pitch); Serial.print("fire is: "); Serial.println(fire); Servo_Yaw.write(yaw); if (0 <= pitch && pitch <= 270) { Servo_Pitch.write(pitch); } if (fire == 1) { Serial.print("Executing fire"); Servo_Rack_Pinion.write(0); delay(1000); Servo_Rack_Pinion.write(200); // angle_servo(0, SERVO_RP_PIN); } } } }The