16x8 RGB Matrix Coding Problems

I have developed this so far:

#include <Tlc5940.h>
#define NUM_CHNLS 48 // The number of LEDs = 3 TLCs * 16

// Column Colour Channels
byte redChannels[16] = {
0 ,1 ,2 ,3 ,4 ,5 ,6 ,7, // TLC1: 0 - 7
16,17,18,19,20,21,22,23}; // TLC2:16-23
byte greenChannels[16] = {
8 ,9 ,10,11,12,13,14,15, // TLC1: 8 - 15
24,25,26,27,28,29,30,31}; // TLC2:24-31
byte blueChannels[16] = {
32,33,34,35,36,37,38,39,
40,41,42,43,44,45,46,47}; // TLC3:32-47
// Row Pins
byte rowPins[8] = {
0,1,2,3,4,5,6,7};

int image1R[16][8] = {
0xfff, 0xeff, 0xdff, 0xcff, 0xbff, 0xaff, 0x9ff, 0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff,
0xeff, 0xdff, 0xcff, 0xbff, 0xaff, 0x9ff, 0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff, 0xfff,
0xdff, 0xcff, 0xbff, 0xaff, 0x9ff, 0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff, 0xfff, 0xeff,
0xcff, 0xbff, 0xaff, 0x9ff, 0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff, 0xfff, 0xeff, 0xdff,
0xbff, 0xaff, 0x9ff, 0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff, 0xfff, 0xeff, 0xdff, 0xcff,
0xaff, 0x9ff, 0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff, 0xfff, 0xeff, 0xdff, 0xcff, 0xbff,
0x9ff, 0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff, 0xfff, 0xeff, 0xdff, 0xcff, 0xbff, 0xaff,
0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff, 0xfff, 0xeff, 0xdff, 0xcff, 0xbff, 0xaff, 0x9ff};

void setup(){
Tlc.init();
for(int i=0; i<8; i++){
pinMode(rowPins*, OUTPUT);*

  • }*
    }
    void loop(){
  • runImage(redChannels, image1R);*
    }
    void runImage(byte &colourChannels, int &imageArray){
  • for(int y=0; y<8; y++){*
  • digitalWrite(rowPins[y], HIGH);*
  • digitalWrite(rowPins[!y], LOW);*
  • for(int i=0; i<16; i++){*
    Tlc.set(colourChannels_[y], imageArray*);
    }
    }
    }[/quote]
    I created the void runImage() function to scan across the rows and set data for the pixels across the columns from image1R (being the first image set for Red Values)
    But I get this error: In function 'void loop()':
    error: 'runImage' was not declared in this scope In function 'void runImage(byte&, int&)':
    /me*_

you need to move (cut and paste) the run image function to the top of the file, or at least declare it there. Remember that your code is compiled top down, so the compiler doesn't even know that your function runImage exists when its called in void loop() because its declaration/definition is compiled after.

In the code below, I declare the function at the head of the file, but leave its definition where you had it.

#include <Tlc5940.h>
#define NUM_CHNLS 48  // The number of LEDs = 3 TLCs * 16

void runImage(byte &colourChannels, int &imageArray); //function declaration - lets the compiler know that you have written this function so the compiler can prepare for it

// Column Colour Channels
byte redChannels[16] = {
 0 ,1 ,2 ,3 ,4 ,5 ,6 ,7,  // TLC1: 0 - 7
 16,17,18,19,20,21,22,23};  // TLC2:16-23
byte greenChannels[16] = {
 8 ,9 ,10,11,12,13,14,15,  // TLC1: 8 - 15
 24,25,26,27,28,29,30,31};  // TLC2:24-31
byte blueChannels[16] = {
 32,33,34,35,36,37,38,39,
 40,41,42,43,44,45,46,47};  // TLC3:32-47
// Row Pins
byte rowPins[8] = {
 0,1,2,3,4,5,6,7};

int image1R[16][8] = {
 0xfff, 0xeff, 0xdff, 0xcff, 0xbff, 0xaff, 0x9ff, 0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff,
 0xeff, 0xdff, 0xcff, 0xbff, 0xaff, 0x9ff, 0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff, 0xfff,
 0xdff, 0xcff, 0xbff, 0xaff, 0x9ff, 0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff, 0xfff, 0xeff,
 0xcff, 0xbff, 0xaff, 0x9ff, 0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff, 0xfff, 0xeff, 0xdff,
 0xbff, 0xaff, 0x9ff, 0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff, 0xfff, 0xeff, 0xdff, 0xcff,
 0xaff, 0x9ff, 0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff, 0xfff, 0xeff, 0xdff, 0xcff, 0xbff,
 0x9ff, 0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff, 0xfff, 0xeff, 0xdff, 0xcff, 0xbff, 0xaff,
 0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff, 0xfff, 0xeff, 0xdff, 0xcff, 0xbff, 0xaff, 0x9ff};

void setup(){
 Tlc.init();
 for(int i=0; i<8; i++){
   pinMode(rowPins[i], OUTPUT);
 }
}

void loop(){
 runImage(redChannels, image1R);
}

void runImage(byte &colourChannels, int &imageArray){
 for(int y=0; y<0; y++){
   digitalWrite(rowPins[y], HIGH);
   digitalWrite(rowPins[!y], LOW);
   for(int i=0; i<16; i++){
     Tlc.set(colourChannels[i][y], imageArray[i]);
   }
 }
}

Hmmm...this has never seemed to matter before, but thanks for that! :slight_smile:

/me

Now that I have changed that, I get this error:

In function 'void loop()':
error: invalid initialization of non-const reference of type 'byte&' from a temporary of type 'byte*' In function 'void runImage(byte&, int&)':

I'm not quite sure what this means as I am not too experienced with C++ functions. Most of this was a mixture of luck and reading example [which are usually about maths]

/me

OK, now I have re-ordered it and added another function [not important] I get another similar error:

#include <Tlc5940.h>
#define NUM_TLCS 3
#define NUM_CHNLS 16*NUM_TLCS // The number of LEDs = 3 TLCs * 16
#define WIDTH 16
#define HEIGHT 8

// Column Colour Channels
byte redChannels[16] = {
0 ,1 ,2 ,3 ,4 ,5 ,6 ,7, // TLC1: 0 - 7
16,17,18,19,20,21,22,23}; // TLC2:16-23
byte greenChannels[16] = {
8 ,9 ,10,11,12,13,14,15, // TLC1: 8 - 15
24,25,26,27,28,29,30,31}; // TLC2:24-31
byte blueChannels[16] = {
32,33,34,35,36,37,38,39,
40,41,42,43,44,45,46,47}; // TLC3:32-47
// Row Pins
byte rowPins[8] = {
0,1,2,3,4,5,6,7};

int image1R[WIDTH][HEIGHT] = {
0xfff, 0xeff, 0xdff, 0xcff, 0xbff, 0xaff, 0x9ff, 0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff,
0xeff, 0xdff, 0xcff, 0xbff, 0xaff, 0x9ff, 0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff, 0xfff,
0xdff, 0xcff, 0xbff, 0xaff, 0x9ff, 0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff, 0xfff, 0xeff,
0xcff, 0xbff, 0xaff, 0x9ff, 0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff, 0xfff, 0xeff, 0xdff,
0xbff, 0xaff, 0x9ff, 0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff, 0xfff, 0xeff, 0xdff, 0xcff,
0xaff, 0x9ff, 0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff, 0xfff, 0xeff, 0xdff, 0xcff, 0xbff,
0x9ff, 0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff, 0xfff, 0xeff, 0xdff, 0xcff, 0xbff, 0xaff,
0x8ff, 0x7ff, 0x6ff, 0x5ff, 0x4ff, 0x3ff, 0x2ff, 0x1ff, 0xff, 0xfff, 0xeff, 0xdff, 0xcff, 0xbff, 0xaff, 0x9ff};

void runImage(byte& colourChannels, int& imageArray){
for(int y=0; y<HEIGHT; y++){
digitalWrite(rowPins[y], HIGH);
digitalWrite(rowPins[!y], LOW);
for(int i=0; i<WIDTH; i++){
Tlc.set(colourChannels_[y], imageArray*);_
_
}_
_
}_
_
}_
void randomColours(){
_
for(int y=0; y<HEIGHT; y++){_
_
digitalWrite(rowPins[y], HIGH);_
_
digitalWrite(rowPins[!y], LOW);_
_
for(int i=0; i<WIDTH; i++){_
_
int randomRed = random(1, 4095); // Generate random number: 1+ so none can ever be off*_
* int randomGreen = random(1, 4095); // Generate random number: 1+ so none can ever be off*
* int randomBlue = random(1, 4095); // Generate random number: 1+ so none can ever be off*
_ Tlc.set(redChannels*, randomRed);
Tlc.set(greenChannels, randomRed);
Tlc.set(blueChannels, randomRed);
delay(100);
}
}
}
void setup(){
randomSeed(analogRead(0));
Tlc.init();
for(int i=0; i<8; i++){
pinMode(rowPins, OUTPUT);
}
}
void loop(){
runImage(redChannels, image1R);
}[/quote]
error: In function 'void runImage(byte&, int&)':
error: invalid types 'unsigned char[int]' for array subscript In function 'void loop()':
/me*_

redChannels is of type byte*.
runImage takes a byte& as first parameter.

I have now sorted this function:

int runImage(byte colourChannels[NUM_COL_CHNLS], int imageArray[WIDTH][HEIGHT]){
for(int y=0; y<HEIGHT; y++){
digitalWrite(rowPins[y], HIGH);
digitalWrite(rowPins[!y], LOW);
for(int i=0; i<WIDTH; i++){
Tlc.set(colourChannels_, imageArray*[y]);_
_
Tlc.update();_
_
delay(10);_
_
}_
_
}_
_
}_
void loop(){
_
runImage(redChannels, image1R);_
_
delay(3000);_
_
}[/quote]*_
Cheers for the help :slight_smile: /me