Firmata | PWN | USB ?

Hi, I'm using firmata on my arduino to be able to controll it with processing the easy way. What i'm doing is altering arduinos analogPin values. In efect that changes the Led's color. Yesterdey i was working on this project for the whole day and at night my head was going to explode just because everytime i want to change the led's color it flashes before it changes. And looking at the flashing thing all day made me sick :S I'm wondering why does it have to turn the led off to be able to turn it back on with a diferent analogPin value. Is it something the PWM on the board does? Is it maybe cause i'm using the 5V power from the USB to power my leds and for comunication, and when i comunicate with arduino the LEDs loose power? (I think it didn't flicker when the program was wihout comunication). Any ideas?

Thanks!

What i'm doing is altering arduinos analogPin values.

Do you mean the value sent to analogWrite(), which affects a digital pin's state?

Post some code...

I'm doing a lot of calculation's and stuff so the code is huge but none of it interfaces with arduino till the point i do the folowing.

      arduino.analogWrite(ledR,x); //Pin for Red
      arduino.analogWrite(ledG,y);//Pin for Green
      arduino.analogWrite(ledB,z); //Pin for Blue

The whole program is in the draw method so what it does is actualy calls arduino.analogWrite() every, lets say 500ms.

Everything works good apart from the fact that everytime this code executes. The Leds go off for a few miliseconds and then light up with new values. Must they always flicker when i comunicate with arduino?

I've written a simple program and uploaded it to arduino that just changes the analog pin's value at random and it didn't flicker at all.

If that code is the only interaction with the Arduino, I'd scrap Firmata and just send a packet to the serial port consisting of a start of packet marker, 3 bytes, and an end of packet marker.

On the Arduino, writing a sketch to receive the serial data, parse the r, g, and b values in the packet, and using digitalWrite to set the LEDs, should be very easy.

I'm only using firmata cause my first atempt didn't work. I've written a program for arduino that listens on the serial port and when data is avalable it stores it in an array, finds the delimiter witch tells him where the data starts and ends for each message and then fires the LED's acordingly. It worked fine when tested with arduino's IDE built in serial montor. But when i tryed sending the data with my processing code. The arduino builtin Leds flickered (witch i guess means that something was passed to arduino) but nothing happened. It seemed like the data sent got lost. I checked the forums for both arduino and processing and as it appears i was doing everything rite. I was using the same COM port as arduino and the code looked ok.

I built my code with one of the examples that came with arduino softwere (the one that turns the led on pin 13 on and of). The code expects characters L or H and sets the digital pin to LOW or HIGH. That worked.

I can't find the code but i'll rewrite it again i guess.. Maybe i'll need help :P