#include Servo servoY; String receivedString = ""; float faceY = 0.0; float faceX = 0.0; float crossY = 0.0; float crossX = 0.0; int step = 0; // Step to track which data point we are processing void setup() { pinMode(LED_BUILTIN, OUTPUT); Serial.begin(9600); servoY.attach(9); servoY.write(90); } void loop() { while (Serial.available()) { char incomingChar = Serial.read(); if (incomingChar == '\n') { // Process the complete string received String cleanedData = cleanString(receivedString); float value = cleanedData.toFloat(); // Assign the value to the correct variable based on the step switch (step) { case 0: faceY = value; break; case 1: faceX = value; break; case 2: crossY = value; break; case 3: crossX = value; step = -1; // Reset step to 0 after the last data point break; } // Clear the buffer for the next data receivedString = ""; step++; // Move to the next data point } else { receivedString += incomingChar; } } delay(100); // Small delay to allow for serial communication } String cleanString(String data) { data.replace("b'", ""); data.replace("'", ""); data.trim(); return data; }