TinyBrite Arduino library first release

TinyBrite Arduino library first release

As mentioned before, I love me some LEDs and have a particular fondness for the MegaBrites, powerful RGB modules that are easy to chain together.  The only issue I encountered in using the hardware was with SPI support or, more specifically, lack thereof.  On certain Arduino’s, like the very tiny Digispark, there is no hardware support for the protocol.

ShiftBrite in action

ShiftBrite in action

For such cases, and for instances where you’re already using the SPI pins or simply when you want to keep things simple, it’s still possible to communicate with the A6281 PWM LED driver that powers the ‘brites by bit-banging the data as required.

Being a big fan both of re-use and of sharing the results of my labour, I packaged this functionality in a library–TinyBrite–and am releasing it now as free software (LGPL’ed).  It works with MegaBrites, ShiftBrites and should work with anything using the A6281 driver.

The library handles all the details of the communication protocol, and lets you send colors down the chain.    Even when you do have SPI on-board, I find TinyBrite nicely encapsulates the details and makes it really easy to setup your lighting.

Each time you send a color, it will be pushed down the line, i.e. set on the ‘brite “nearest” to the Arduino, that brite’s previous value being sent down the chain to the next, and so on.

In the simplest case, all you need to do to use the library is:

// include the library
#include <TinyBrite.h>

// define the number of 'brites in the chain
#define num_chained_brites    3

// and the pins on the arduino that we're using
#define clockpin  0
#define latchpin  2
#define datapin   3

// create the megabrite chain object
TinyBrite brite_chain(num_chained_brites, TINYBRITE_AUTOUPDATE_ENABLE); 
// three daisy-chained *brites, auto-updated.

// tell it which pins to use
brite_chain.setup(datapin, clockpin, latchpin);

// now: send colors as desired, using sendColor(R,G,B)
brite_chain.sendColor(0, 0, TINYBRITE_COLOR_MAXVALUE); // blue

brite_chain.sendColor(TINYBRITE_COLOR_MAXVALUE, 0, 0); // red

brite_chain.sendColor(500, 500, 0); // any mix of RGB

// our 3-chained brites will now look like:
// Arduino -> Yellow -> Red -> Blue

The library is pretty lightweight and the “BriteChain” example that comes with it and exercises a chain by fading MegaBrites in and out a few times and rotating a series of colors compiles to under 2.5k for the Digistump Digispark, leaving over half the space on the ATTiny available for other uses.

Check it out, try it out, and let me know what you think!

Leave a Reply