Pages: [1]   Go Down
Author Topic: RBGLed Library  (Read 1556 times)
0 Members and 1 Guest are viewing this topic.
Santa Barbara
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Web programming < Arduino programming
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
    http://github.com/citrus/RGBLed


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:
/**
* 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

http://citrusme.com/
Logged

Newcastle NSW Australia
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
RalimTek
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
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 smiley-grin

Thanks, and keep up the good work.
Logged

Cybot

Santa Barbara
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Web programming &lt; Arduino programming
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

-Spencer
Logged

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 96
Why is it so?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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;}
« Last Edit: October 27, 2010, 01:44:21 pm by 32teeth » Logged

Pages: [1]   Go Up
Jump to: