Martin's corner on the web

RGB LED

I’ve never played with RGB LEDs before, got myself couple to try out on Funky v2. The Funky v2 only has 1 pin with PWM, so I used the SoftPWM library instead:

An Arduino library to produce PWM signals on any arbitrary pin.

It was originally designed for use controlling the brightness of LEDs, but could be modified to control servos and other low frequency PWM controlled devices as well.

It uses a single hardware timer on the micro-controller to generate up to 20 PWM channels.

So I soldered some resistors on the anodes and used one of the SoftPWM example sketches to try it out, it produces a beautiful rainbow pulsating light:

#include <SoftPWM.h> //https://code.google.com/p/rogue-code/wiki/SoftPWMLibraryDocumentation

#define DELAY 40

uint8_t leds[8] = {13,8,2,1};

void setup()
{
  SoftPWMBegin();

  for (int i = 0; i < 8; i++)
    SoftPWMSet(leds[i], 0);

  SoftPWMSetFadeTime(ALL, 30, 200);

}

void loop()
{
  int i;

  for (i = 0; i < 3; i++)   {     
          SoftPWMSet(leds[i+1], 255);     
          SoftPWMSet(leds[6-i], 255);     
          SoftPWMSet(leds[i], 0);     
          SoftPWMSet(leds[7-i], 0);     
          delay(DELAY);   
   }      
  delay(250);      

for (i = 3; i > 0; i--)
  {
    SoftPWMSet(leds[i-1], 255);
    SoftPWMSet(leds[8-i], 255);
    SoftPWMSet(leds[i], 0);
    SoftPWMSet(leds[7-i], 0);
    delay(DELAY);
  }

  delay(250);
}

IMG_1997

IMG_1999

 

This may come in handy in some future project.

 

One thought on “RGB LED

  1. Pingback: Temperature to RGB LED | Martin's corner on the web