Go Down

Topic: RBGLed Library (Read 2397 times) previous topic - next topic


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 / http://citrusme.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!




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.


Glad you like it and might find it useful! If I find some time to revisit this i'll incorporate your feature requests.



Oct 27, 2010, 08:43 pm Last Edit: Oct 27, 2010, 08:44 pm by 32teeth Reason: 1
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;}

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131