Multidimensional Array Charlieplexing 90 LEDs (10 pins)

Hi,

I would like to make a multidimensional array of 10 rows * 9 columns for Charlieplexing 90 LEDs. The array represents the positions of the LEDs.

LED00 LED01 LED02 LED03 LED04 LED05 LED06 LED07 LED08

LED10 LED11 LED12 LED13 LED14 LED15 LED16 LED17 LED18

LED20 LED21 LED22 LED23 LED24 LED25 LED26 LED27 LED28

LED30 LED31 LED32 LED33 LED34 LED35 LED36 LED37 LED38

LED40 LED41 LED42 LED43 LED44 LED45 LED46 LED47 LED48

LED50 LED51 LED52 LED53 LED54 LED55 LED56 LED57 LED58

LED60 LED61 LED62 LED63 LED64 LED65 LED66 LED67 LED68

LED70 LED71 LED72 LED73 LED74 LED75 LED76 LED77 LED78

LED80 LED81 LED82 LED83 LED84 LED85 LED86 LED87 LED88

LED90 LED91 LED92 LED93 LED94 LED95 LED96 LED97 LED98

Below is my code.

int Pin1 = 2;
int Pin2= 3;
int Pin3 = 4;
int Pin4 = 5;
int Pin5 = 6;
int Pin6 = 7;
int Pin7 = 8;
int Pin8 = 9;
int Pin9 = 10;
int Pin10 = 11;
int a = 0;
int b = 0;
int LEDNumber [10][10];


void setup() 
{
  
}


void OnLED (LEDNumber[a][b])
{
  if (a == 0)
  {
    pinMode(Pin1, OUTPUT);
    digitalWrite (Pin1, LOW);
    if (b == 0)
    {
      pinMode(Pin2, OUTPUT);
      pinMode(Pin3, INPUT);
      pinMode(Pin4, INPUT);
      pinMode(Pin5, INPUT);
      pinMode(Pin6, INPUT);
      pinMode(Pin7, INPUT);
      pinMode(Pin8, INPUT);
      pinMode(Pin9, INPUT);
      pinMode(Pin10, INPUT);
      digitalWrite (Pin2, HIGH);
    }
  }
}


void loop() 
{
  OnLED ([0][0]);
  delay(50);
}

The compiler stuck at void OnLED (LEDNumber[a]), it says error: variable or field 'OnLED' declared void
I have made Instructables.com for the project, may have a look.
Thanks for your help in advance. :slight_smile:
https://www.instructables.com/Charlieplexing-90-LEDs-10-Pins/

Try this
Untested beyond compiling

int Pin1 = 2;
int Pin2 = 3;
int Pin3 = 4;
int Pin4 = 5;
int Pin5 = 6;
int Pin6 = 7;
int Pin7 = 8;
int Pin8 = 9;
int Pin9 = 10;
int Pin10 = 11;
int a = 0;
int b = 0;
int LEDNumber [10][10];


void setup()
{
}

void OnLED (byte a, byte b)
{
  if (a == 0)
  {
    pinMode(Pin1, OUTPUT);
    digitalWrite (Pin1, LOW);
    if (b == 0)
    {
      pinMode(Pin2, OUTPUT);
      pinMode(Pin3, INPUT);
      pinMode(Pin4, INPUT);
      pinMode(Pin5, INPUT);
      pinMode(Pin6, INPUT);
      pinMode(Pin7, INPUT);
      pinMode(Pin8, INPUT);
      pinMode(Pin9, INPUT);
      pinMode(Pin10, INPUT);
      digitalWrite (Pin2, HIGH);
    }
  }
}


void loop()
{
  OnLED (0, 0);
  delay(50);
}

Thank you
UKHeliBob

It managed to compile. The PCB boards have not come. Yet tested. :slight_smile:

Do you understand what was wrong ?

don't you want something like following? (compiles, untested)
not sure how you determine which LEDs are active

byte rowPins [] = { 3, 4, 5, 6 };
byte colPins [] = { 7, 8, 9, 10, 11 };
#define N_ROW      sizeof(rowPins)
#define N_COL      sizeof(colPins)

byte ledState [N_COL][N_ROW] = {};  // 0 == LOW == Off

// -----------------------------------------------------------------------------
void setup()
{
    for (unsigned i = 0; i < N_ROW; i++)
        pinMode (rowPins [i], OUTPUT);

    for (unsigned i = 0; i < N_COL; i++)
        pinMode (colPins [i], INPUT);
}

// -----------------------------------------------------------------------------
// LEDs are On when row pin is HIGH and
// col pin is configured as an OUTPUT and LOW
// allowing current to flow from row to col pin.
// LED is Off when col pin is configure as INPUT.

void refresh (void)
{
    for (unsigned col = 0; col < N_COL; col++)  {
        digitalWrite (colPins [col], LOW);      // set LOW to sink current
        pinMode (colPins [col], OUTPUT);

        for (unsigned row = 0; row < N_ROW; row++)
            digitalWrite (rowPins [row], ledState [row][col]);

        pinMode (colPins [col], INPUT);         // removes sink

#define REFRESH_DELAY   10
        delay (REFRESH_DELAY);
    } 
}

// -----------------------------------------------------------------------------
void setLed (
    byte    state,
    int     col,
    int     row )
{
    ledState [row][col] = state;
}

// -----------------------------------------------------------------------------
void
routineSettingLedsOnOff (void)
{
    // ???
}

// -----------------------------------------------------------------------------
void loop()
{
    refresh ();
    routineSettingLedsOnOff ();
}

Why not lose all the duplication of this:

int Pin1 = 2;
int Pin2= 3;
int Pin3 = 4;
int Pin4 = 5;
int Pin5 = 6;
int Pin6 = 7;
int Pin7 = 8;
int Pin8 = 9;
int Pin9 = 10;
int Pin10 = 11;

and make it nice and succinct with an array:

byte pins [10] = {2,3,4,5,6,7,8,9,10,11} ;

You only need a byte for a pin number. Similarly the array of LED states may only need to be
of type boolean.

Pin 1
Pin 2
Pin 3
Pin 4
Pin 5
Pin 6
Pin 7
Pin 8
Pin 9
Pin 10
LED No.

0 1 INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT LED00
0 INPUT 1 INPUT INPUT INPUT INPUT INPUT INPUT INPUT LED01
0 INPUT INPUT 1 INPUT INPUT INPUT INPUT INPUT INPUT LED02
0 INPUT INPUT INPUT 1 INPUT INPUT INPUT INPUT INPUT LED03
0 INPUT INPUT INPUT INPUT 1 INPUT INPUT INPUT INPUT LED04
0 INPUT INPUT INPUT INPUT INPUT 1 INPUT INPUT INPUT LED05
0 INPUT INPUT INPUT INPUT INPUT INPUT 1 INPUT INPUT LED06
0 INPUT INPUT INPUT INPUT INPUT INPUT INPUT 1 INPUT LED07
0 INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT 1 LED08
INPUT 0 1 INPUT INPUT INPUT INPUT INPUT INPUT INPUT LED10
INPUT 0 INPUT 1 INPUT INPUT INPUT INPUT INPUT INPUT LED11
INPUT 0 INPUT INPUT 1 INPUT INPUT INPUT INPUT INPUT LED12
INPUT 0 INPUT INPUT INPUT 1 INPUT INPUT INPUT INPUT LED13
INPUT 0 INPUT INPUT INPUT INPUT 1 INPUT INPUT INPUT LED14
INPUT 0 INPUT INPUT INPUT INPUT INPUT 1 INPUT INPUT LED15
INPUT 0 INPUT INPUT INPUT INPUT INPUT INPUT 1 INPUT LED16
INPUT 0 INPUT INPUT INPUT INPUT INPUT INPUT INPUT 1 LED17
1 0 INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT LED18
INPUT INPUT 0 1 INPUT INPUT INPUT INPUT INPUT INPUT LED20
INPUT INPUT 0 INPUT 1 INPUT INPUT INPUT INPUT INPUT LED21
INPUT INPUT 0 INPUT INPUT 1 INPUT INPUT INPUT INPUT LED22
INPUT INPUT 0 INPUT INPUT INPUT 1 INPUT INPUT INPUT LED23
INPUT INPUT 0 INPUT INPUT INPUT INPUT 1 INPUT INPUT LED24
INPUT INPUT 0 INPUT INPUT INPUT INPUT INPUT 1 INPUT LED25
INPUT INPUT 0 INPUT INPUT INPUT INPUT INPUT INPUT 1 LED26
1 INPUT 0 INPUT INPUT INPUT INPUT INPUT INPUT INPUT LED27
INPUT 1 0 INPUT INPUT INPUT INPUT INPUT INPUT INPUT LED28
INPUT INPUT INPUT 0 1 INPUT INPUT INPUT INPUT INPUT LED30
INPUT INPUT INPUT 0 INPUT 1 INPUT INPUT INPUT INPUT LED31
INPUT INPUT INPUT 0 INPUT INPUT 1 INPUT INPUT INPUT LED32
INPUT INPUT INPUT 0 INPUT INPUT INPUT 1 INPUT INPUT LED33
INPUT INPUT INPUT 0 INPUT INPUT INPUT INPUT 1 INPUT LED34
INPUT INPUT INPUT 0 INPUT INPUT INPUT INPUT INPUT 1 LED35
1 INPUT INPUT 0 INPUT INPUT INPUT INPUT INPUT INPUT LED36
INPUT 1 INPUT 0 INPUT INPUT INPUT INPUT INPUT INPUT LED37
INPUT INPUT 1 0 INPUT INPUT INPUT INPUT INPUT INPUT LED38
INPUT INPUT INPUT INPUT 0 1 INPUT INPUT INPUT INPUT LED40
INPUT INPUT INPUT INPUT 0 INPUT 1 INPUT INPUT INPUT LED41
INPUT INPUT INPUT INPUT 0 INPUT INPUT 1 INPUT INPUT LED42
INPUT INPUT INPUT INPUT 0 INPUT INPUT INPUT 1 INPUT LED43
INPUT INPUT INPUT INPUT 0 INPUT INPUT INPUT INPUT 1 LED44
1 INPUT INPUT INPUT 0 INPUT INPUT INPUT INPUT INPUT LED45
INPUT 1 INPUT INPUT 0 INPUT INPUT INPUT INPUT INPUT LED46
INPUT INPUT 1 INPUT 0 INPUT INPUT INPUT INPUT INPUT LED47
INPUT INPUT INPUT 1 0 INPUT INPUT INPUT INPUT INPUT LED48

Pin 1
Pin 2
Pin 3
Pin 4
Pin 5
Pin 6
Pin 7
Pin 8
Pin 9
Pin 10
LED No.

INPUT INPUT INPUT INPUT INPUT 0 1 INPUT INPUT INPUT LED50
INPUT INPUT INPUT INPUT INPUT 0 INPUT 1 INPUT INPUT LED51
INPUT INPUT INPUT INPUT INPUT 0 INPUT INPUT 1 INPUT LED52
INPUT INPUT INPUT INPUT INPUT 0 INPUT INPUT INPUT 1 LED53
1 INPUT INPUT INPUT INPUT 0 INPUT INPUT INPUT INPUT LED54
INPUT 1 INPUT INPUT INPUT 0 INPUT INPUT INPUT INPUT LED55
INPUT INPUT 1 INPUT INPUT 0 INPUT INPUT INPUT INPUT LED56
INPUT INPUT INPUT 1 INPUT 0 INPUT INPUT INPUT INPUT LED57
INPUT INPUT INPUT INPUT 1 0 INPUT INPUT INPUT INPUT LED58
INPUT INPUT INPUT INPUT INPUT INPUT 0 1 INPUT INPUT LED60
INPUT INPUT INPUT INPUT INPUT INPUT 0 INPUT 1 INPUT LED61
INPUT INPUT INPUT INPUT INPUT INPUT 0 INPUT INPUT 1 LED62
1 INPUT INPUT INPUT INPUT INPUT 0 INPUT INPUT INPUT LED63
INPUT 1 INPUT INPUT INPUT INPUT 0 INPUT INPUT INPUT LED64
INPUT INPUT 1 INPUT INPUT INPUT 0 INPUT INPUT INPUT LED65
INPUT INPUT INPUT 1 INPUT INPUT 0 INPUT INPUT INPUT LED66
INPUT INPUT INPUT INPUT 1 INPUT 0 INPUT INPUT INPUT LED67
INPUT INPUT INPUT INPUT INPUT 1 0 INPUT INPUT INPUT LED68
INPUT INPUT INPUT INPUT INPUT INPUT INPUT 0 1 INPUT LED70
INPUT INPUT INPUT INPUT INPUT INPUT INPUT 0 INPUT 1 LED71
1 INPUT INPUT INPUT INPUT INPUT INPUT 0 INPUT INPUT LED72
INPUT 1 INPUT INPUT INPUT INPUT INPUT 0 INPUT INPUT LED73
INPUT INPUT 1 INPUT INPUT INPUT INPUT 0 INPUT INPUT LED74
INPUT INPUT INPUT 1 INPUT INPUT INPUT 0 INPUT INPUT LED75
INPUT INPUT INPUT INPUT 1 INPUT INPUT 0 INPUT INPUT LED76
INPUT INPUT INPUT INPUT INPUT 1 INPUT 0 INPUT INPUT LED77
INPUT INPUT INPUT INPUT INPUT INPUT 1 0 INPUT INPUT LED78
INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT 0 1 LED80
1 INPUT INPUT INPUT INPUT INPUT INPUT INPUT 0 INPUT LED81
INPUT 1 INPUT INPUT INPUT INPUT INPUT INPUT 0 INPUT LED82
INPUT INPUT 1 INPUT INPUT INPUT INPUT INPUT 0 INPUT LED83
INPUT INPUT INPUT 1 INPUT INPUT INPUT INPUT 0 INPUT LED84
INPUT INPUT INPUT INPUT 1 INPUT INPUT INPUT 0 INPUT LED85
INPUT INPUT INPUT INPUT INPUT 1 INPUT INPUT 0 INPUT LED86
INPUT INPUT INPUT INPUT INPUT INPUT 1 INPUT 0 INPUT LED87
INPUT INPUT INPUT INPUT INPUT INPUT INPUT 1 0 INPUT LED88
1 INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT 0 LED90
INPUT 1 INPUT INPUT INPUT INPUT INPUT INPUT INPUT 0 LED91
INPUT INPUT 1 INPUT INPUT INPUT INPUT INPUT INPUT 0 LED92
INPUT INPUT INPUT 1 INPUT INPUT INPUT INPUT INPUT 0 LED93
INPUT INPUT INPUT INPUT 1 INPUT INPUT INPUT INPUT 0 LED94
INPUT INPUT INPUT INPUT INPUT 1 INPUT INPUT INPUT 0 LED95
INPUT INPUT INPUT INPUT INPUT INPUT 1 INPUT INPUT 0 LED96
INPUT INPUT INPUT INPUT INPUT INPUT INPUT 1 INPUT 0 LED97
INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT 1 0 LED98

Hey all,

I would like to blink every single LED and create patterns.
Please have a look at the truth table.

For example. LED 00 to LED 08, the common ground pin is 1.
LED 10 to LED 18, the common ground pin is 2.
LED 20 to LED 28, the common ground pin is 3.

LED 30 to LED 38, the common ground pin is 4.

LED 40 to LED 48, the common ground pin is 5.

LED 50 to LED 58, the common ground pin is 6.

LED 60 to LED 68, the common ground pin is 7.

LED 70 to LED 78, the common ground pin is 8.

LED 80 to LED 88, the common ground pin is 9.

LED 90 to LED 98, the common ground pin is 10.

The high pins vary with the LED number.
Attached is the truth table.

Thanks in advance. :slight_smile:

Hey,

Attached is the truth table.

Charlieplexing 90 LEDs.pdf (156 KB)

Hey,

Just an update. Here is my sample code, can you please suggest to me how to simplify this code, especially the pins? Thanks in advance.

int Pin0 = 2;
int Pin1 = 3;
int Pin2 = 4;
int Pin3 = 5;
int Pin4 = 6;
int Pin5 = 7;
int Pin6 = 8;
int Pin7 = 9;
int Pin8 = 10;
int Pin9 = 11;

void setup()
{
}

void OnLED (int a, int b)
{
  if (a == 0)
  {
    pinMode(Pin0, OUTPUT);
    digitalWrite (Pin0, HIGH);
    if (b == 0)
    {
      pinMode(Pin0, OUTPUT);
      pinMode(Pin1, OUTPUT);
      pinMode(Pin2, INPUT);
      pinMode(Pin3, INPUT);
      pinMode(Pin4, INPUT);
      pinMode(Pin5, INPUT);
      pinMode(Pin6, INPUT);
      pinMode(Pin7, INPUT);
      pinMode(Pin8, INPUT);
      pinMode(Pin9, INPUT);
      digitalWrite (Pin1, LOW);
    }
    if (b == 1)
    {
      pinMode(Pin0, OUTPUT);
      pinMode(Pin1, INPUT);
      pinMode(Pin2, OUTPUT);
      pinMode(Pin3, INPUT);
      pinMode(Pin4, INPUT);
      pinMode(Pin5, INPUT);
      pinMode(Pin6, INPUT);
      pinMode(Pin7, INPUT);
      pinMode(Pin8, INPUT);
      pinMode(Pin9, INPUT);
      digitalWrite (Pin2, LOW);
    }
    if (b == 2)
    {
      pinMode(Pin0, OUTPUT);
      pinMode(Pin1, INPUT);
      pinMode(Pin2, INPUT);
      pinMode(Pin3, OUTPUT);
      pinMode(Pin4, INPUT);
      pinMode(Pin5, INPUT);
      pinMode(Pin6, INPUT);
      pinMode(Pin7, INPUT);
      pinMode(Pin8, INPUT);
      pinMode(Pin9, INPUT);
      digitalWrite (Pin3, LOW);
    }
    if (b == 3)
    {
      pinMode(Pin0, OUTPUT);
      pinMode(Pin1, INPUT);
      pinMode(Pin2, INPUT);
      pinMode(Pin3, INPUT);
      pinMode(Pin4, OUTPUT);
      pinMode(Pin5, INPUT);
      pinMode(Pin6, INPUT);
      pinMode(Pin7, INPUT);
      pinMode(Pin8, INPUT);
      pinMode(Pin9, INPUT);
      digitalWrite (Pin4, LOW);
    }
    if (b == 4)
    {
      pinMode(Pin0, OUTPUT);
      pinMode(Pin1, INPUT);
      pinMode(Pin2, INPUT);
      pinMode(Pin3, INPUT);
      pinMode(Pin4, INPUT);
      pinMode(Pin5, OUTPUT);
      pinMode(Pin6, INPUT);
      pinMode(Pin7, INPUT);
      pinMode(Pin8, INPUT);
      pinMode(Pin9, INPUT);
      digitalWrite (Pin5, LOW);
    }
    if (b == 5)
    {
      pinMode(Pin0, OUTPUT);
      pinMode(Pin1, INPUT);
      pinMode(Pin2, INPUT);
      pinMode(Pin3, INPUT);
      pinMode(Pin4, INPUT);
      pinMode(Pin5, INPUT);
      pinMode(Pin6, OUTPUT);
      pinMode(Pin7, INPUT);
      pinMode(Pin8, INPUT);
      pinMode(Pin9, INPUT);
      digitalWrite (Pin6, LOW);
    }
    if (b == 6)
    {
      pinMode(Pin0, OUTPUT);
      pinMode(Pin1, INPUT);
      pinMode(Pin2, INPUT);
      pinMode(Pin3, INPUT);
      pinMode(Pin4, INPUT);
      pinMode(Pin5, INPUT);
      pinMode(Pin6, INPUT);
      pinMode(Pin7, OUTPUT);
      pinMode(Pin8, INPUT);
      pinMode(Pin9, INPUT);
      digitalWrite (Pin7, LOW);
    }
    if (b == 7)
    {
      pinMode(Pin0, OUTPUT);
      pinMode(Pin1, INPUT);
      pinMode(Pin2, INPUT);
      pinMode(Pin3, INPUT);
      pinMode(Pin4, INPUT);
      pinMode(Pin5, INPUT);
      pinMode(Pin6, INPUT);
      pinMode(Pin7, INPUT);
      pinMode(Pin8, OUTPUT);
      pinMode(Pin9, INPUT);
      digitalWrite (Pin8, LOW);
    }
    if (b == 8)
    {
      pinMode(Pin0, OUTPUT);
      pinMode(Pin1, INPUT);
      pinMode(Pin2, INPUT);
      pinMode(Pin3, INPUT);
      pinMode(Pin4, INPUT);
      pinMode(Pin5, INPUT);
      pinMode(Pin6, INPUT);
      pinMode(Pin7, INPUT);
      pinMode(Pin8, INPUT);
      pinMode(Pin9, OUTPUT);
      digitalWrite (Pin9, LOW);
    }
  }
}

void loop()
{
  for (a = 0; a < 9; a++)
  {
    for (b = 0; b < 8; b++)
    {
      OnLED (a, b);
      delay(100); 
    }
    for (b = 0; b < 8; b++)
    {
      OnLED (a, b);
      delay(100); 
    }
    for (b = 0; b < 8; b++)
    {
      OnLED (a, b);
      delay(100); 
    }
    for (b = 0; b < 8; b++)
    {
      OnLED (a, b);
      delay(100); 
    }
    for (b = 0; b < 8; b++)
    {
      OnLED (a, b);
      delay(100); 
    }
    for (b = 0; b < 8; b++)
    {
      OnLED (a, b);
      delay(100); 
    }
    for (b = 0; b < 8; b++)
    {
      OnLED (a, b);
      delay(100); 
    }
    for (b = 0; b < 8; b++)
    {
      OnLED (a, b);
      delay(100); 
    }
    for (b = 0; b < 8; b++)
    {
      OnLED (a, b);
      delay(100); 
    }
    for (b = 0; b < 8; b++)
    {
      OnLED (a, b);
      delay(100); 
    }
  }
}

Charlieplexing_90_LEDs_inverted.ino (33.2 KB)

Here is my updated truth table. The pins start from pin 0.

Charlieplexing 90 LEDs.pdf (156 KB)

Start by putting the pin numbers in an array. Then create a 2 dimensional array with the row being the value of a and the columns being the required value (HIGH, or LOW) for the pins associated with the value of a

Then, given the value of a you can select a row in the array and iterate through the values in that row setting the LED states as appropriate

A further refinement would be not to store HIGH/LOW in the second array but to use the bit values in an int variable in a simple array indexed by the value of a, but I suggest that you do it the other way first

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.