Go Down

Topic: A charlieplexing library (Read 2887 times) previous topic - next topic


Sep 26, 2012, 12:03 pm Last Edit: Oct 03, 2012, 08:29 am by marcuserronius Reason: 1
Hi, all!
When I went looking for a library to help with charlieplexing an array of LEDs, I couldn't find one that supported larger numbers of LEDs, while making it simple to address each LED. So I wrote one. :D I'm calling it ChuckPlex, and I hope others will find it as useful as I do.

It can help you configure your array: telling you how many pins you will need for a particular number of nodes and how to wire them. It addresses nodes by index, hiding the HIGHs, LOWs, INPUTs and OUTPUTs. It supports using as many pins as you can spare, allowing over a hundred LEDs on most boards, or thousands on the Mega. If the chosen pins are PWM pins, it supports writing analog values in addition to digital ones.

Some example code:
Code: [Select]
#include <ChuckPlex.h>

int pins[] = {2,3,4,5};
ChuckPlex plex = ChuckPlex(pins,4);

void setup(){
  // no setup!

// blink the fourth led in the array
void loop(){
  // light the fourth led
  // turn off all leds

Please try it out if you are inclined, and I would love to hear feedback!
latest version: ChuckPlex v1.0.1


0) Put all of those strings into flash memory!

1) It seems like there's a lot of bloat. You pull in the floating point library and a ton of strings, which is unnecessary. Although I'm not sure if gcc is smart enough to ignore all of those if the user doesn't end up using the displayConnections function.

2) You need to use memcpy for getting the pins array, because you don't know what the user will do with it after they've passed you the pointer.

4) Add some documentation. You should at least say which methods are "you should use this" and which ones are "you probably won't need this" --- I'm guessing that write is the "main" method.

5) write's value argument should have a default value, because it's pretty frequent that you just want it on full power.


Thanks for the feedback :) This is my first project working with Arduino, so I don't know a lot of the tricks that may seem obvious to others.

Regarding the strings, I was originally going to use an external utility to display the connections, but decided to pull it into the project. Probably it would be better to conditionally compile that in only if it's in develop modeā€¦

memcpy: thanks for the pointer, didn't think of that.

documentation: since it was simple, I was just letting the examples do the documenting :) But that's pretty lazy, so I'll get something proper in there.

Again, thanks for the feedback!


So it appears that gcc will leave out the the strings and floating point library if the user doesn't call the displayConnections() method. If the method is only used the one time for setup, is there a cause for concern about it? Or would it be a more elegant solution to move it back to an external utility after all? Thanks for all your help :)

Go Up