Go Down

Topic: 3by3 led cube control by matrix not working (Read 1 time) previous topic - next topic

zer044


I have made a  Led cube got it working i have programed it but i wanna move to the next step of saving the image of each pattern as a byte array.....
i couldn't use byte because it only accepts 8 values and i have 9 leds.. I wrote the arrays as ints instead but when i upload it nothing happens to the cube..(power shows on mega just the cube doesnt work).

If there is a way to still do it with bytes that may help if it has any advantages working with bytes..

i tried to write some code but nothing happens here it is...

Code: [Select]
int levelPins[] = {22,23,24};
int colPins[] = {30,31,32,33,34,35,36,37,38};

int first[3][9] = {
111000000,
011100000,
001110000,
};

void setup () {
 //set all output
 for (int i=0; i<3; i++) {
   pinMode(levelPins[i], OUTPUT);
 }
 for (int j=0; j<9; j++) {
   pinMode(colPins[j], OUTPUT);

 }
}

void show (int image[3][9]) {
for (int level=0; level<3; level++) {
 digitalWrite(levelPins[level], LOW);
 
  for (int col=0; col < 9; col++) {
   int pixel = image[level][col];
   
 if (pixel == 1) {digitalWrite(colPins[col], HIGH);}

delay(30);
digitalWrite(colPins[col], LOW);
      } // col for
  digitalWrite(levelPins[level], HIGH);
  } // level for
} // end of show


void loop() {

show(first);
 }

Here is a video of the working led cube without images saved as arrays.. that code is somewhere in ...http://arduino.cc/forum/index.php/topic,69174.0.html
http://www.youtube.com/watch?v=INvgBCGcrGM

fungus

Code: [Select]

int first[3][9] = {
111000000,
011100000,
001110000,
};


This isn't an array of three rows of nine ints, it's an array of three ints, try this:

Code: [Select]

int first[3] = {
111000000,
011100000,
001110000,
};


Then you need to modify your "show()" function to look at the the individual bits in each int:

Code: [Select]
void show (int image[3]) {
for (int level=0; level<3; level++) {
  digitalWrite(levelPins[level], LOW);
   
   for (int col=0; col < 9; col++) {
    int bitmask = 1<<col;
    int pixel = image[level]&bitMask;

    if (pixel != 0) {digitalWrite(colPins[col], HIGH);}
...

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

zer044


Code: [Select]

int first[3][9] = {
111000000,
011100000,
001110000,
};


This isn't an array of three rows of nine ints, it's an array of three ints, try this:



So will declaring ,
111000000,
011100000,
001110000,
without the [9] make 3 arrays size 9? what was wrong with the first 1 i dnt get it but i will try ur method, i just want to understand what im doing. Thx for the reply.

zer044

also i dont understand this bit 
Code: [Select]
for (int col=0; col < 9; col++) {
    int bitmask = 1<<col;
    int pixel = image[level]&bitMask;

Grumpy_Mike

That part of the code takes the value in image[level] and splits it into it's individual bits and places them one by one in the variable pixel.
The << is a shift operation and the & is a logical AND.
The logical AND with the bit mask sets all the bits to zero apart from the bits in the bit mask.
The << shifts the bitmask one place to the left each time round the loop.

Go Up