How can I do this with PWM? Hard drive clock RGB

Hi to every one. I'm making my own Hard drive persitance of vision clock, and thanks to the help of this forum I've done great advances, i'm almost done.
What I'm trying to do now is make an RGB background for the clock, like shown on the "RGB effect.png" attached image.
I've started with something simple like a gradient of only one color, something like this:
and this is my code for that:

void interrupt() // INTERRUPCION
{
  go=true;
}
void loop()
{
  if(go)
  {
    for (int i=255; i>0; i--)
    {
      analogWrite(pinG, i);  // pin G is a PWN pin connected to a RGB led strip through an uln2003
      delayMicroseconds(10);
    }
    digitalWrite(pinG, LOW); 
    go=false;
  }
}

but the result of this is shown on this video. Its like if I am seeing the On and OFF of the PWM cycle... I'm pretty sure that's the problem, but... how can I solve it? I know its possible because I've seen videos (like the image attached) that made it using arduino. I've also tried using two colors at the same time to mix the the on and off cycles but still getting the same arbitrary effect.

Thanks to everyone!

rgb effect.PNG

Post your code, not just an excerpt.

AWOL:
Post your code, not just an excerpt.

Sorry, here is the complete code, but there is nothing more to see

#include <Servo.h>
#define pinG         3    //Green pin \
#define pinB         5    //Blue pin   |->> RGB led Strip through ULN2003
#define pinR        11    //Red pin   /

Servo esc;
volatile boolean go = false;
void setup()
{
  attachInterrupt(0, interrupt, FALLING);
  esc.attach(9);
  Serial.begin(9600);
  esc.writeMicroseconds(1100);
  delay(3000);
  esc.writeMicroseconds(1415);      //This is for start the hard drive motor.
  delay(500);
}

void interrupt() // This is triggered by a magnet glued on the plate and a hall effect sensor
{
  go=true;
}
void loop()
{
  if(go)
  {
    for (int i=255; i>0; i--)
    {
      analogWrite(pinG, i);  // pin G is a PWN pin connected to a RGB led strip through an uln2003
      delayMicroseconds(10);
    }
    digitalWrite(pinG, LOW); 
    go=false;  // I do this to ensure that the loop is running only one time with each revolution of the plate
  }
}

I've attached another image showing the hardware, it's not he same hardware i'm using in the video but works the same way.

Thanks again! :slight_smile:

I think that you'll have to go with a faster PWM frequency, ? 490 Hz is too slow.

Hi, There is some PWM info on the http://ArduinoInfo.Info WIKI here:
http://arduino-info.wikispaces.com/Arduino-PWM-Frequency

How about using a low pass filter to convert the PWM to an analogue voltage?

Hi, thanks for all the answers!
I've checked the frequency of the PWM and found a way to modify it using this code

void setPwmFrequency(int pin, int divisor) {
  byte mode;
  if(pin == 5 || pin == 6 || pin == 9 || pin == 10) {
    switch(divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 64: mode = 0x03; break;
      case 256: mode = 0x04; break;
      case 1024: mode = 0x05; break;
      default: return;
    }
    if(pin == 5 || pin == 6) {
      TCCR0B = TCCR0B & 0b11111000 | mode;
    } else {
      TCCR1B = TCCR1B & 0b11111000 | mode;
    }
  } else if(pin == 3 || pin == 11) {
    switch(divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 32: mode = 0x03; break;
      case 64: mode = 0x04; break;
      case 128: mode = 0x05; break;
      case 256: mode = 0x06; break;
      case 1024: mode = 0x7; break;
      default: return;
    }
    TCCR2B = TCCR2B & 0b11111000 | mode;
  }
}

http://playground.arduino.cc/Code/PwmFrequency
But it only seems to work if divide by 8.

Any way I didn't know that pwm could be converted to analogue voltage, I think that would be the solution!
I've found this: Arduino Playground - RegulatedPositiveVoltageBooster which has this circuit
But I don't know if that would work, and I also have some quiestiones about that circuit.

  1. What's the difference between Analog Out (Aout) and Vout? Wich of them should I use to power the RGB led strip? I guess its Aout, but can I simply ignore Vout? Do I need it?
  2. It says that Aout goes from 0V to 5V, can I use the Aout to control the ULN2003 so the leds will recieve 0V to 12V (from an ATX Pc power supply)???

Thanks again! :slight_smile: