How to use Serial to communicate to Servos w/ LED lights

Hi, I am new to Processing and Arduino. I want the servos to turn either right or left when it receives the serial numbers. So when the lights turn green, the servos turn left, when the lights turn red, the servos turn right.

Arduino

#include <Servo.h>

Servo servoLeft;
Servo servoRigtht;

int green = 8;
int red = 2;
byte incomingByte;
byte lastByte;

void setup() {
  Serial.begin(9600);  
  pinMode(green, OUTPUT);
  pinMode(red, OUTPUT);

  servoLeft.attach(10);
  servoRight.attach(9); 
}

void loop() {
    lastByte = incomingByte;
    
    //Serial.available() == "open";   //cut
    if (Serial.available()) {
    incomingByte = Serial.read();
     //   digitalWrite(green, HIGH);  //cut
 // delay(incomingByte);              //cut
    }

    if (incomingByte > lastByte) {
//        digitalWrite(green, HIGH);  //cut
//        delay(400);                 //cut
        digitalWrite(green, LOW);
        delay(400);
        digitalWrite(green, HIGH);
        digitalWrite(red, LOW);
        delay(1000);
        
        turnLeft();
        delay(2000);
        turnRight();
        delay(2000);
}
    if (incomingByte < lastByte) {
        digitalWrite(green, LOW); 
        digitalWrite(red, LOW);
        delay(400);
        digitalWrite(red, HIGH);
        delay(1000);
    }
 }

 void turnLeft() {
  servoLeft.write(0);
  servoRight.write(0);
 }


void turnRight() {
  servoLeft.write(180);
  servoRight.write(180);
}
import processing.serial.*;

Serial myPort;

Table table;

void setup() {
  size(630, 480);
  background(0);
  
  myPort = new Serial(this, Serial.list()[0], 9600);
  
  table = loadTable("NVDA.csv", "header");
   for(TableRow row : table.rows()) {
    byte open = byte(row.getInt("Open"));
    //float open2 = float(row.getInt("Open"));
    println("open price is (" + open + ")");
    
    myPort.write(open);
    delay(4000);
 }
}

void draw() {
  //fill(200, 50, 100);
  //ellipse(width/2, height/2, 50, 50);
}

Robin2 has a really useful serial handling basics tutorial topic.

I want the servos to turn either right or left when it receives the serial numbers.

What does the code actually do? How does that differ from what you want?

The Arduino recieve data (numerals) from Processing and Processing is receiving data from a csv table. In Arduino, when ever it reads the value increasing, it blinks the LED green. When ever the value goes down, it blinks LED red.

Right now, I want the servos to follow along with the instructions under the if conditions in Arduino. I was wondering if there are flexible ways to do so.

I have a circuit set up with LED green and red lights on the breadboard.

I hope that answer your questions?

Right now, I want the servos to follow along with the instructions under the if conditions in Arduino.

This is what you want. The reality is? How can we help you fix your problem if we don't know what the problem is?

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example.

...R

PaulS:
What does the code actually do? How does that differ from what you want?

PaulS:
This is what you want. The reality is? How can we help you fix your problem if we don't know what the problem is?

There is this error 'servoRight' was not declared in this scope.

void turnLeft() {
servoLeft.write(0);
servoRight.write(0);
}

void turnRight() {
servoLeft.write(180);
servoRight.write(180);
}

Servo servoRigtht;