Arduino Forum

Forum 2005-2010 (read only) => General => Exhibition => Topic started by: citrus on Oct 09, 2010, 09:37 pm

Title: RBGLed Library
Post by: citrus on Oct 09, 2010, 09:37 pm
This is my first arduino library.. It's just a simple RBG led controller with a few basic functions..

The library is available on github:

Here's the public API:

   RGBLed(int red, int green, int blue);
   void on(int color);
   void mix(int color1, int color2);
   void off();
   void red();
   void green();
   void blue();
   void yellow();
   void purple();
   void turquoise();
   void animate();
   void next();
   int  mode;

I've included an example sketch that has a button for toggling the mode and a potentiometer for controlling the animation speed. The LED starts off so don't forget to press the 'next' button!

Code: [Select]
* RGBLed Library Example
* Copyright 2010 Spencer Steffen, spencer<at>citrusme<dot>com /

#include <RGBLed.h>

#define BTN_PIN A4
#define POT_PIN A5

int _btnDown;
int _value;
int _delay;

// Initialize the LED with pwm pins.
RGBLed led = RGBLed(9,10,11);

void setup() {
 pinMode(BTN_PIN, INPUT);
 pinMode(POT_PIN, INPUT);

void loop() {

 Serial.print("MODE: ");
 _btnDown = digitalRead(BTN_PIN);
 if (_btnDown == 1) {;

 if (led.mode < ANIMATE) return;  
 _value = analogRead(POT_PIN);
 _delay = map(_value, 0, 1023, 2, 99);

Here's how my board is setup for the example sketch.


Check it out and post your thoughts.. Thanks!

Title: Re: RBGLed Library
Post by: Cybot_Rules on Oct 12, 2010, 07:37 am
i love the concept, mayb you could make a function so you can say wether it drives the outputs high or low (dependign if its anode or cathode commen) and i would really love a function to send a Hue value to it, once you mkae it easy to send the hue or RGB value to it im definatly over the moon, im building a custom xbox case that is full of rgb leds and im planing to have the colour fade across the xbox, so if i could use this to send the hue to like 10 rgb leds one after another i would be over the moon :D

Thanks, and keep up the good work.
Title: Re: RBGLed Library
Post by: citrus on Oct 22, 2010, 07:13 pm
Glad you like it and might find it useful! If I find some time to revisit this i'll incorporate your feature requests.

Title: Re: RBGLed Library
Post by: 32teeth on Oct 27, 2010, 08:43 pm
On our project:
Sparky Jr. RGB LED (
controller for video mages fightstick light up we use a jumper connected to a pin.

by default the code is for common cathode. if the jumper is plugged in. the code switches to common anode.

Code: [Select]

#define cathode LOW
#define anode HIGH
int active = HIGH;
int signal = LOW;

int on = cathode;
int off = anode;

set jumper pin and pull down (set HIGH as default)
test for active common anode jumper pin
reset variables accordingly for commone anode
pinMode(jumper, INPUT);
digitalWrite(jumper, HIGH);
if(digitalRead(jumper) == LOW){on = anode;off = cathode;active = LOW;signal = HIGH;}