Can't get processing to talk to arduino.

I’ve made the following code which takes values from processing and sends them to an arduino.
once they reach the arduino they should be read and turned into analog values for the led brightness to be set to.

The processing code is definitely talking to the arduino as I can see the serial lights flickering correctly but the brightness isn’t changing; the data is clearly being interpreted incorrectly at the arduino end but processing hogs the serial port so I can’t find out what’s going wrong.

Can anyone point me to what I’ve messed up in the below code?

Processing code first…

import processing.serial.*;
// create a new instance of the serial classes and assign it to 'myPort'
Serial myPort;

import controlP5.*;

ControlP5 cp5;
int myColor = color(0,0,0);

int valueA = 0;
int valueB = 0;
int valueC = 0;
Slider abc;

void setup() {
  size(200,200);
  noStroke();
  cp5 = new ControlP5(this);
  
  // add a horizontal sliders, the value of this slider will be linked
  // to variable 'sliderValue' 
  cp5.addSlider("valueA")
     .setPosition(20,50)
     .setRange(0,254)
     ;
     
  cp5.addSlider("valueB")
     .setPosition(20,100)
     .setRange(0,254)
     ;
     
  cp5.addSlider("valueC")
     .setPosition(20,150)
     .setRange(0,254)
     ;
     
    myPort = new Serial(this, "COM10", 9600);
}

void draw() {
  background(120);
  myPort.write(int(valueA));
  myPort.write(int(valueB));
  myPort.write(int(valueC));
}

And the arduino code…

int incomingByte[3]; 
int led = 13;


void setup() {
  // initialize serial communication - make sure its the same as expected in the processing code
  Serial.begin(9600);
  pinMode(led, OUTPUT);
  
}

void loop() {
  // check to make sure there's 3 bytes of data waiting
  if (Serial.available() >= 3) {
    // read the oldest byte in the serial buffer:
    for (int i=0; i<3; i++) {
      // read each byte
      incomingByte[i] = Serial.read();
    }
  }

  analogWrite(led, incomingByte[1]);
}

Both are modifications of code from the following link…
http://luckylarry.co.uk/arduino-projects/using-processing-to-send-values-to-arduino/

Thanks in advance for any suggestions.

As your flow of information is PC to Arduino only, it is easy to add debug prints to the PC.

Adding this to the Processing sketch handles the printing to the Processing console

void serialEvent(Serial p) {
  while (p.available()!=0) {
    print(char(p.read()));
  }
}

This is the debug Arduino loop

void loop() {
  // check to make sure there's 3 bytes of data waiting
  if (Serial.available() >= 3) {
    // read the oldest byte in the serial buffer:
    for (int i = 0; i < 3; i++) {
      // read each byte
      incomingByte[i] = Serial.read();
      Serial.print(incomingByte[i]);
      if (i != 2) {
        Serial.write(',');
      } else {
        Serial.println();
      }
    }
  }
  analogWrite(led, incomingByte[1]);
}

Now you can see that the problem.
You do not have any delimiter that tells you which byte belongs where, so the mapping of your sliders is arbitrary for each start.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

…R