Charlieplex Library for Arduino
Author:  Alexander Brevig
Contact: alexanderbrevig@gmail.com

Navigation


Current version

1.0 2009-03-12: Initial Release


History

1.0 2009-03-12: Initial Release


Description

Charlieplex is a library for the Arduino.

It is created to help make readable charlieplex code. It hides the pinMode, and digitalWrite calls for the user.

You can try my Charlieplex Schematic Creator.


Download, install and import

Download here: Attach:Charlieplex.zip

Put the Charlieplex folder in "hardware\libraries\".

In the Arduino IDE, create a new sketch (or open one) and

select from the menubar "Sketch->Import Library->Charlieplex".

Once the library is imported, an "#include Charlieplex.h" line will appear

at the top of your Sketch.


Creation

Charlieplex(byte* userPins, byte numberOfUserPins)

#define NUMBER_OF_PINS 3
byte pins[] = {11,12,13};
Charlieplex charlieplex = Charlieplex(pins,NUMBER_OF_PINS);

Instanciates a Charlieplex object that uses pins 11, 12 and 13.

You'll need to define some charliePins as well. This is the syntax:

charliePin led = { 0 , 2 }; //HIGH when current flows from 11 to 13


Functions

void charlieWrite(charliePin pin,bool state)

Sets a charliePin HIGH or LOW

void setVcc(byte pin)

Set a pin as vcc (OUTPUT:HIGH)

void setGnd(byte pin)

Set a pin as gnd (OUTPUT:LOW)

void clear()

Set all pins as (INPUT)


Example

  1. /*
  2. ||
  3. || @author Alexander Brevig
  4. || @version 1.0
  5. ||
  6. */
  7. /*
  8. This code is tested with built in led @ pin 13, a led connected with anode 12 cathode 13, and a last led connected with anode 11 cathode 13
  9. I would love feedback at alexanderbrevig@gmail.com
  10. */
  11.  
  12. #include <Charlieplex.h>
  13.  
  14. #define NUMBER_OF_PINS 3
  15. //define pins in the order you want to adress them
  16. byte pins[] = {11,12,13};
  17.  
  18. //initialize object
  19. Charlieplex charlieplex = Charlieplex(pins,NUMBER_OF_PINS);
  20.  
  21. //individual 'pins' , adress charlieplex pins as you would adress an array
  22. charliePin led1 = { 1 , 2 }; //led1 is indicated by current flow from 12 to 13
  23. charliePin led2 = { 0 , 1 };
  24. charliePin led3 = { 0 , 2 };
  25.  
  26. boolean singleOn = false;
  27.  
  28.  
  29. void setup(){ /*nothing*/ }
  30.  
  31. void loop(){
  32.   if (singleOn){ charlieplex.clear(); }
  33.  
  34.   charlieplex.charlieWrite(led1,HIGH);
  35.   delay(1000);
  36.   charlieplex.charlieWrite(led2,HIGH);
  37.   delay(1000);
  38.   charlieplex.charlieWrite(led3,HIGH);
  39.   delay(1000);
  40.  
  41.   singleOn=!singleOn;
  42. }


FAQ

How can I use multiple Charlieplexs?

Charlieplex is a class. Therefore to Charlieplex multiple digital pins, you must create an instance for each of them. In the example above, a Charlieplex instance (Charlieplex charlieplex) is bound to the digital pins 11, 12 and 13

#define NUMBER_OF_PINS 3
byte pins[] = {11,12,13};
Charlieplex charlieplex = Charlieplex(pins,NUMBER_OF_PINS);

To add a Charlieplex bound to digital pin 6, 7, 8 and 9, you could create the following instance charlieplex2:

#define NUMBER_OF_PINS2 4
byte pins2[] = {6,7,8,9};
Charlieplex charlieplex2 = Charlieplex(pins2,NUMBER_OF_PINS2);

And now it's just to use whatever function is wanted on both:

//update instances and possibly fire funcitons
  charlieplex1.clear()
  charlieplex2.charlieWrite(led,HIGH);


Information about this page

Part of AlphaBeta Libraries.
Last Modified: July 24, 2012, at 04:24 PM
By: matelot

Share