Hiho,
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 -------------------------------------------------------------------------------
Firmata.begin();
// ----------------------------------------------------------------------------
Serial.begin(9600);
//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?? -------------------------------------------------
while(Firmata.available())
Firmata.processInput();
// 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
}