user4974: I know this has been asked before, but I'm new to Arduino and Processing, and I'm trying to take this step by step.
I would like to pass an RGB value from processing, into Arduino via the Serial.Write/Read.
I have my Processing as:
void draw(){

  //orange colour in RGB values
  color _rgbColor = color(255, 40, 0);

  //convert colour into hex
  String _hexColor = hex(_rgbColor, 6);

  //convert colour into binary
  String _binaryColor = binary(_rgbColor);

  //pass colour to port
  myPort.write(_hexColor);
  delay(500);
}

I assume I can just pass the HEX value straight across, right?
First problem I get is that I can't debug what my Arduino device is getting (when I run the Processing program, the Serial Monitor wont work. Seems like I can only use one or the other). I can print the myPort.read within my Processing after the delay, and I get:

-1

So I'm not quite sure what I'm doing wrong there. 
On the Arduino side, I'm using Serial.read() to retrieve the Serial data, which I assume will all be broken down into bytes, so I need to then convert it into a HEX formate, right?
----- Update -----
I now know that I need to break down my color variable into a char-message. I'm guessing I can do something like this then, for example: And then on the other side (Arduino), I need to rebuild the message, right?
if(mousePressed == true){
    //Red
     myPort.write('2'); 
     myPort.write('5'); 
     myPort.write('5');
     myPort.write(','); 

     //Green
     myPort.write('0'); 
     myPort.write('3'); 
     myPort.write('0');
     myPort.write(','); 

     //Blue
     myPort.write('0'); 
     myPort.write('0'); 
     myPort.write('0');
     myPort.write('\n'); 
  }

My Arduino script is as follows, is this an okay route to go down?
String message;
void loop() {

  int _size = Serial.available();

  if(_size > 0){

    char value = Serial.read();
    message += value;

    //full message received (255,255,255)
    if(message.length() == 11){
      String _red = message.substring(0,3);
      String _green = message.substring(4,7);
      String _blue = message.substring(8,11);
      Serial.println("R:" + _red + " G:" + _green + " B:" + _blue);

      //apply to light system
      setColour(_red.toInt(), _green.toInt(), _blue.toInt());

      //clear buffer
      message = "";
      Serial.flush();
    }
  }
}


user2881: Add print(_hexColor); to you processing sketch. The value it's sending should appear in the Processing Console (at the bottom)

user37899: I know I'm late, but actually got a working solution, when I was working out a solution for this.
Code in Processing assuming variable myPort is handled in setup():
void draw() {
    int r = 255;
    int g = 123;
    int b = 2;
    myPort.write('S'); // tell the arduino to do something with leds
    myPort.write(r);
    myPort.write(g);
    myPort.write(b);
}

Code for Arduino loop:
void loop() {
  int r;
  int g;
  int b;
  if(Serial.available()) {   
    if(Serial.read() == 'S') {
      while(!Serial.available()){}
      r = Serial.read();
      while(!Serial.available()){}
      g = Serial.read();
      while(!Serial.available()){}
      b = Serial.read();
    }
    delay(10); // some recovery time, not sure if nessecary

    // do something with rgb values
  }
}

This works for me with every possible RGB range. It's not the most elegant solution, but by far better then converting between strings/chars and ints with different bit counts on different devices.

4974: <p>I know this has been asked before, but I'm new to Arduino and Processing, and I'm trying to take this step by step.</p>

<p>I would like to pass an RGB value from processing, into Arduino via the Serial.Write/Read.</p>

<p>I have my Processing as:</p>

<pre><code>void draw(){

  //orange colour in RGB values
  color _rgbColor = color(255, 40, 0);

  //convert colour into hex
  String _hexColor = hex(_rgbColor, 6);

  //convert colour into binary
  String _binaryColor = binary(_rgbColor);

  //pass colour to port
  myPort.write(_hexColor);
  delay(500);
}
</code></pre>

<p>I assume I can just pass the HEX value straight across, right?</p>

<p>First problem I get is that I can't debug what my Arduino device is getting (when I run the Processing program, the Serial Monitor wont work. Seems like I can only use one or the other). I can print the myPort.read within my Processing after the delay, and I get:</p>

<blockquote>
  <p>-1</p>
</blockquote>

<p>So I'm not quite sure what I'm doing wrong there. </p>

<p>On the Arduino side, I'm using Serial.read() to retrieve the Serial data, which I assume will all be broken down into bytes, so I need to then convert it into a HEX formate, right?</p>

<p>----- Update -----</p>

<p>I now know that I need to break down my color variable into a char-message. I'm guessing I can do something like this then, for example: And then on the other side (Arduino), I need to rebuild the message, right?</p>

<pre><code>if(mousePressed == true){
    //Red
     myPort.write('2'); 
     myPort.write('5'); 
     myPort.write('5');
     myPort.write(','); 

     //Green
     myPort.write('0'); 
     myPort.write('3'); 
     myPort.write('0');
     myPort.write(','); 

     //Blue
     myPort.write('0'); 
     myPort.write('0'); 
     myPort.write('0');
     myPort.write('\n'); 
  }
</code></pre>

<p>My Arduino script is as follows, is this an okay route to go down?</p>

<pre><code>String message;
void loop() {

  int _size = Serial.available();

  if(_size &gt; 0){

    char value = Serial.read();
    message += value;

    //full message received (255,255,255)
    if(message.length() == 11){
      String _red = message.substring(0,3);
      String _green = message.substring(4,7);
      String _blue = message.substring(8,11);
      Serial.println("R:" + _red + " G:" + _green + " B:" + _blue);

      //apply to light system
      setColour(_red.toInt(), _green.toInt(), _blue.toInt());

      //clear buffer
      message = "";
      Serial.flush();
    }
  }
}
</code></pre>
 2881: <p>Add <code>print(_hexColor);</code> to you processing sketch. The value it's sending should appear in the Processing Console (at the bottom)</p>
 37899: <p>I know I'm late, but actually got a working solution, when I was working out a solution for this.</p>

<p>Code in Processing assuming variable <code>myPort</code> is handled in <code>setup()</code>:</p>

<pre class="lang-java prettyprint-override"><code>void draw() {
    int r = 255;
    int g = 123;
    int b = 2;
    myPort.write('S'); // tell the arduino to do something with leds
    myPort.write(r);
    myPort.write(g);
    myPort.write(b);
}
</code></pre>

<p>Code for Arduino loop:</p>

<pre class="lang-cpp prettyprint-override"><code>void loop() {
  int r;
  int g;
  int b;
  if(Serial.available()) {   
    if(Serial.read() == 'S') {
      while(!Serial.available()){}
      r = Serial.read();
      while(!Serial.available()){}
      g = Serial.read();
      while(!Serial.available()){}
      b = Serial.read();
    }
    delay(10); // some recovery time, not sure if nessecary

    // do something with rgb values
  }
}
</code></pre>

<p>This works for me with every possible RGB range. It's not the most elegant solution, but by far better then converting between strings/chars and ints with different bit counts on different devices.</p>
