Issue with controlling LED Matrix using Arduino Nano and LED driver

i am working on a project that invovles the use of an Arduino Nano and LED driver (TLC5940). The goal of the project is to give the Arduino a matrix full of binary values and to have those values control an LED matrix of the same size. For the purpose of prototyping, I am using a matrix with 6 rows and 3 columns. Wherever there is a 1 in the matrix --> corresponding LED should turn ON. Likewise, 0 --> LED turned OFF.

The problem I am facing is that the for loop I am using is resulting in the LED matrix displaying each column of values one by one onto the entire 6x3 LED matrix. For example, if the matrix (3x3 for sake of space) appears as follows:
1, 0, 1,
0, 1, 0,
1, 0, 0,
it would result in the LED matrix displaying the entire first and third row ON, then the entire second row ON, then the entire first row ON, and repeat.

Instead, I would like it to display the first and third row ON but only within the first column. Then only the second row turned ON, but only within the second column, and so on.

Code and Sample Matrix can be found in this link: Arduino Nano LED matrix 6x3 - Pastebin.com

Hello yeabutno

Post your sketch, well formated, with well-tempered comments and in so called code tags "</>" and schematic to see how we can help.

#include <tlc_config.h>

#include "Tlc5940.h"

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("--- Started Program ---");

  // Setting pin modes (change to INPUT if an input device - i.e. the
  // potentiometer input pin)
  pinMode(A0, OUTPUT);
  pinMode(A1, OUTPUT);
  pinMode(A2, OUTPUT);
  pinMode(A3, OUTPUT);
  pinMode(A4, OUTPUT);
  pinMode(A5, OUTPUT);
  pinMode(2, OUTPUT);
  digitalWrite(2, LOW);
  pinMode(4, OUTPUT);
  digitalWrite(4, LOW);
  pinMode(5, OUTPUT);
  digitalWrite(5, LOW);
  pinMode(6, OUTPUT);
  digitalWrite(6, LOW);
  pinMode(7, OUTPUT);
  digitalWrite(7, LOW);
  pinMode(8, OUTPUT);
  digitalWrite(8, LOW);

  Tlc.init(0);  // set brightness to 0 for all channels (columns) to start

  // Print a message to indicate that the setup function is completed/no errors
  // there.
  Serial.println("Finished setup. Beginning Loop.");
}

void loop() {
  // put your main code here, to run repeatedly:
  // Naming row pins
  int rows[] = {2, 4, 5, 6, 7, 8, 12, A0};

  // Naming column pins
  int cols[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};

  // simple initial test
  Serial.println("Turning on and off simple matrix");
  for (int i = 0; i < 8; i++) {
    Tlc.set(i, 4095);
  }
  Tlc.set(0, 4095);
  Tlc.set(2, 4095);
  Tlc.set(3, 4095);

  digitalWrite(2, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(8, HIGH);

  Tlc.update();
  delay(1000);
  Tlc.clear();

  Serial.println("Starting matrix animation");
  int col1[6][3] = {
      1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0,
  };

  for (int j = 0; j < 3; j++) {
    Serial.print("col value is: ");
    Serial.println(j);
    digitalWrite(cols[j], LOW);
    for (int i = 0; i < 6; i++) {
      Serial.print("matrix value is: ");
      Serial.println(col1[i][j]);
      digitalWrite(rows[i], col1[i][j]);
    }
    delay(1000);
  }
}


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