Modify the data sent via Firmata


I´m sending data from a slider in Processing to my Arduino board for controlling an RGB LED.
I´m using Firmata as transportation protocol.

How can I modify my Arduino sketch so that Arduino will only listen to the Pins 9, 10 and 11? These are the pins which Processing applies the data to.
I can´t use the Standard firmata sketch because

  • I have much more custom functionality in my sketch (I deleted it in the sketch for seeing through more easily) and
  • because I have to process the data first BEFORE I send them to the pins 9, 10, 11 of my Arduino board,

So how can I - inside the Arduino sketch - catch the values which have been sent to the pins 9, 10, 11 of my Arduino board by Processing and store them into integer variables?
In my Arduino sketch below I´d like to store the values in the int variables brightness_r, brightness_g and brightness_b.

Can you help me?
I would be very happy about this…

Dim RGB-led.
The leds have a common anode (+5V) (and resistor) and get into 
the channels 9, 10 and 11 of the Arduino board.
Receive the values for R, G, B via Firmata, save them into the variables 
brightness_r, brightness_g, brightness_b.
Process the data and write the resulting values to the pins 9, 10, 11 
with analogWrite(...).

// Firmata-Stuff------------------------------------------------------------------------------

#include <Boards.h>
#include <Firmata.h>

// -------------------------------------------------------------------------------

int led_r = 9;
int led_g = 10;
int led_b = 11;

int brightness_r;      // e.g. 0
int brightness_g;      // e.g. 0
int brightness_b;      // e.g. 255

void setup() 

// Firmata-Stuff -------------------------------------------------------------------------------

// ----------------------------------------------------------------------------

  //Setup led1
  pinMode(led_r, OUTPUT);
  pinMode(led_g, OUTPUT);
  pinMode(led_b, OUTPUT);
  digitalWrite(led_r, HIGH);  // switch LED off as pins 9, 10, 11 are Arduino inputs, not outputs!
  digitalWrite(led_g, HIGH);
  digitalWrite(led_b, HIGH);

void loop() 
// Firmata-Stuff --- What to do now?? -------------------------------------------------

  // brightness_r = data which has originally been sent to Pin 9 by Processing. 
  // brightness_g = data which has originally been sent to Pin 10 by Processing. 
  // brightness_b = data which has originally been sent to Pin 11 by Processing.   

// -------------------------------------------------------------------------------
  // write values to leds.

  analogWrite(led_r, 255 - brightness_r);   // red led
  analogWrite(led_g, 255 - brightness_g);   // green led
  analogWrite(led_b, 255 - brightness_b);   // blue led

Firmata turns your Arduino into a mindless extension of the PC. You can't easily diddle with the way that Firmata controls the hardware.

And, frankly I can't see why you think you need to. Processing should be controlling the pins, sending data at the appropriate time/rate/etc.

OK, the reason why the modifications on the values received via Firmata must be processed inside the Arduino code is that Procesing will no longer be the controller application. It was good for testing purposes but actually vvvv should talk to my Arduino board instead of Processing. In vvvv I´m connecting boxes with cables and some steps of my data processings are not optimal there. I will use vvvv for creating graphical interfaces FOR controlling my Arduino board. So far my Arduino code also contains a quite complex touch sensor which is easier to handle in Arduino. I erased it above for keeping the code short enough.

Well, I´m able to process the data of my Touch-Sensor and write it to an Arduino pin using Firmata so that vvvv can fetch the value. This works with


Now I need to realize the return. Fetching the value, storing it in a variable, processing it and write the modified value to an output pin. How? Simple serial communication does not work well.

What is vvvv? The answer is no. Write real code you do not / can not use Firmata other than as a blind slave.