Let's Make Robots!

RGB Mixer – Processing to Arduino

guibot's picture
send values from processing to arduino



RGB Mixer - Processing to Arduino


void setup()
// declare the serial comm at 9600 baud rate

// output pins
pinMode(9, OUTPUT); // red
pinMode(10, OUTPUT); // green
pinMode(11, OUTPUT); // blue

// another output pin o be used as GROUND
pinMode(8, OUTPUT); // ground
digitalWrite(8, LOW);

void loop()
// call the returned value from GetFromSerial() function
case 'R':
analogWrite(9, GetFromSerial());
case 'G':
analogWrite(11, GetFromSerial());
case 'B':
analogWrite(10, GetFromSerial());


// read the serial port
int GetFromSerial()
while (Serial.available()<=0) {
return Serial.read();


RGB Mixer - Processing to Arduino

import processing.serial.*;
Serial port;

sliderV sV1, sV2, sV3;

color cor;

void setup() {
size(500, 500);

println("Available serial ports:");


// create 3 instances of the sliderV class

void draw() {


// send sync character
// send the desired value

Slider Class - www.guilhermemartins.net
based on www.anthonymattox.com slider class
class sliderV {
int x, y, w, h, p;
color cor;
boolean slide;

x = _x;
y = _y;
w = _w;
h = _h;
p = 90;
cor = _cor;
slide = true;

void render() {

p = h-(mouseY-y);
if (p<0) {
else if (p>h) {

RGB Mixer - Processing to Arduino

RGB Mixer - Processing to Arduino

RGB Mixer - Processing to Arduino

Comment viewing options

Calculon320's picture

Calculon has never used processing until now, and this was a perfect way to get into it for him.
He's been building on the sketch to add Save/Load functions.


(save/load isn't working yet). The LED is part of a dekstop polysmurf flower:

Note: the RGB that Calculon used (the RadioShack variety) uses a common anode. Thus, he had to change the 'duino sketch to pull LOW for each PWM pin, and map the variables to switch high and low (since 255 = off).

Thanks for your trailblazing, Guibot!

guibot's picture

I changed the 'A, 'B', 'C' sync characters to 'R', 'G' and 'B'

voodoobot's picture

hrmmm...2 things.

In the arduino code you have a switch/case but don't have a default case. From what the manual says, it's not necessary but should be included for good coding practices.

The getfromserial method uses <=, less than or equal to.  value.available() >0 would seem to make more sense

If nothing comes through this value will be -1(per manual) again, no default case to catch this.

Just some recommended changes.

Aside from that, it's a pretty cool project.  :)

guibot's picture

I agree, but if we go for good practices I have start by using the resistors in series before the led  :) ....  regarding the code I don't understand your 2nd suggestion.. If you feel it is really important please send it to me and I will change the code, thnx  ;)

voodoobot's picture

I should have said some changes that might make things more robust if you get into more complex coding.

I hear ya though, good circuit design is a different story and I take all suggestions when I can get em.  :)

As for the changes, I only mention them because things can tend to bite you in the butt later if you don't take into account all possible values. As for the <= thing, I guess you are guaranteed to do something even if you don't have a valid value for the switch select(you had a, b, and c, but -1 would be a value you'd also get on an empty read) as in the case of -1 being returned for the .available() method. I assume the switch/case without the "default" case just ignores the value and goes back to the loop. My suggestion is to close off that unknown by making sure that you only catch the values you are looking for by only reading if there is a value hence the .available() > 0. What you have works though, I just like playing around with the code sometimes to make sure I know that it's doing what I expect it to...  :)