Pages: [1]   Go Down
Author Topic: 16x8 RGB Matrix Coding Problems  (Read 860 times)
0 Members and 1 Guest are viewing this topic.
Keynsham, UK
Offline Offline
Full Member
***
Karma: 0
Posts: 224
I like for loops and walks on the beach,
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: April 11, 2009, 09:58:31 am by PA_Skins » Logged

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

0
Offline Offline
Full Member
***
Karma: 0
Posts: 175
---
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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]);
   }
 }
}
Logged

Keynsham, UK
Offline Offline
Full Member
***
Karma: 0
Posts: 224
I like for loops and walks on the beach,
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

/me
Logged

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

Keynsham, UK
Offline Offline
Full Member
***
Karma: 0
Posts: 224
I like for loops and walks on the beach,
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

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

Keynsham, UK
Offline Offline
Full Member
***
Karma: 0
Posts: 224
I like for loops and walks on the beach,
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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(){
  randomSeed(analogRead(0));
  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
Logged

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

0
Offline Offline
Edison Member
*
Karma: 8
Posts: 1411
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Logged

Keynsham, UK
Offline Offline
Full Member
***
Karma: 0
Posts: 224
I like for loops and walks on the beach,
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley /me
Logged

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

Pages: [1]   Go Up
Jump to: