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!
/**
* 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);
Serial.begin(115200);
}
void loop() {
Serial.print("MODE: ");
Serial.println(led.mode);
_btnDown = digitalRead(BTN_PIN);
if (_btnDown == 1) {
led.next();
delay(250);
return;
}
if (led.mode < ANIMATE) return;
led.animate();
_value = analogRead(POT_PIN);
_delay = map(_value, 0, 1023, 2, 99);
delay(_delay);
}
Here's how my board is setup for the example sketch.
Check it out and post your thoughts.. Thanks!
-Spencer