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.

AWOL

Quote
111000000,
011100000,
001110000,

Why are some constants in decimal, and others in octal?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

zer044


Quote
111000000,
011100000,
001110000,

Why are some constants in decimal, and others in octal?


Umm... I have no idea what you are talking about so i guess i got some reading to do.

What i was trying to achieve is each line represents a level on my cube each 1 or 0 represents the led in that levels status.
so "011100000" represents 1st led off second on third on fourth on... ect..

AWOL

Quote
so "011100000" represents 1st led off second on third on fourth on... ect.

In C, a constant starting with a zero is taken to be an octal value, in this case, the equivalent decimal value is 2 392 064.

If you want a binary constant, prefix the number with "0b".
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

zer044


Quote
so "011100000" represents 1st led off second on third on fourth on... ect.

In C, a constant starting with a zero is taken to be an octal value, in this case, the equivalent decimal value is 2 392 064.

If you want a binary constant, prefix the number with "0b".


I just realized what i was doing wrong with my original code..... 
i declared my array wrong
Code: [Select]
int first[3][9] = {
111000000,
011100000,
001110000,
};


Should have been ...
Code: [Select]
int first[3][9] = {
{1, 1, 1, 0, 0, 0, 0, 0, 0},
{0, 1, 1, 1, 0, 0, 0, 0, 0},
{0, 0, 1, 1, 1, 0, 0, 0, 0},
};


if i want declare them as bytes i should do this?
Code: [Select]
int first[3]= {
0b111000000,
0b011100000,
0b001110000,
};


do i have to change the array type to byte? also i tried this method but used the "B" prefix and it only let me use upto 8 numbers.. i have 9 leds so thats a problem.


AWOL

#9
Aug 26, 2011, 07:12 pm Last Edit: Aug 26, 2011, 07:18 pm by AWOL Reason: 1
Quote
used the "B" prefix and it only let me use upto 8 numbers

If you need 9 bits, use "0b" as the prefix.
See reply #7.
The "B" prefix is an Arduino convenience.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview