Go Down

### Topic: 16x8 RGB Matrix Coding Problems (Read 2463 times)previous topic - next topic

##### Apr 11, 2009, 04:27 pmLast Edit: Apr 11, 2009, 04:58 pm by PA_Skins Reason: 1
I have developed this so far:

Quote
#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);
}
}
}

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
"C++ : Where friends have access to your private members." - Gavin Russell Baker

#### FusiveResonance

#1
##### Apr 11, 2009, 04:50 pm
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.

Code: [Select]
`#include <Tlc5940.h>#define NUM_CHNLS 48  // The number of LEDs = 3 TLCs * 16void 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 Channelsbyte redChannels[16] = { 0 ,1 ,2 ,3 ,4 ,5 ,6 ,7,  // TLC1: 0 - 7 16,17,18,19,20,21,22,23};  // TLC2:16-23byte greenChannels[16] = { 8 ,9 ,10,11,12,13,14,15,  // TLC1: 8 - 15 24,25,26,27,28,29,30,31};  // TLC2:24-31byte blueChannels[16] = { 32,33,34,35,36,37,38,39, 40,41,42,43,44,45,46,47};  // TLC3:32-47// Row Pinsbyte 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]);   } }} `

#2
##### Apr 11, 2009, 04:53 pm
Hmmm...this has never seemed to matter before, but thanks for that!

/me
"C++ : Where friends have access to your private members." - Gavin Russell Baker

#3
##### Apr 11, 2009, 04:59 pm
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
"C++ : Where friends have access to your private members." - Gavin Russell Baker

#4
##### Apr 11, 2009, 05:45 pm
OK, now I have re-ordered it and added another function [not important] I get another similar error:

Quote
#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(){
Tlc.init();
for(int i=0; i<8; i++){
pinMode(rowPins, OUTPUT);
}
}

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

error: In function 'void runImage(byte&, int&)':
error: invalid types 'unsigned char[int]' for array subscript In function 'void loop()':

/me
"C++ : Where friends have access to your private members." - Gavin Russell Baker

#### florinc

#5
##### Apr 11, 2009, 10:33 pm
redChannels is of type byte*.
runImage takes a byte& as first parameter.

#6
##### Apr 11, 2009, 10:47 pm
I have now sorted this function:

Quote
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);
}

Cheers for the help /me
"C++ : Where friends have access to your private members." - Gavin Russell Baker

Go Up