Go Down

Topic: trouble with void function. (Read 702 times) previous topic - next topic

WonderTiger

Mar 05, 2013, 09:22 pm Last Edit: Mar 05, 2013, 09:33 pm by WonderTiger Reason: 1
I'm busy with programming my cube. Now I'm pretty much done with my code, however I want to simplify my code. This is where I have some problems:
Code: [Select]

int Array1[5][6] = {{ , , , , ,}, {, , , , ,}, etc}; // this is an animation for my led cube
int Array2[5][6] = {{ , , , , ,}, {, , , , ,}, etc}; // this is another animation for my led cube
void shift_out(char animation);

void loop(){
shift_out(Array1[a][b]); //'[a][b]' is used in the for loop from shift_out
delay(1000);
shift_out(Array2[a][b]);
}

void shift_out(char animation){
for(int a=0; a<5; a++){
     digitalWrite(latchPin, LOW);
     for(int b=0; b<6; b++){
       shiftOut(dataPin, clockPin, MSBFIRST, animation); // animation need to become Array1[a][b] or Array2[a][b]
     }
     digitalWrite(latchPin, HIGH);
     delay(1);
   }
}


So if I want Array1 to show on my led cube, I need to take Array1[a][b ] to shift_out, when I go to shift_out 'animation' need to be Array1[a][b ]. When I want to show Array2 on my led cube, I need to take Array2[a][b ] to shift_out, when I go to shift_out 'animation' need to be Array2 [a][b ] I know its not working with char( a and b need to be declared aswell), I only wrote char in the piece of code to make it more clear what I want to do.

I can get it working if I give a and b a specific number. Like if I say Array[1][1], Array[1][1] can be written to an integer. Then I have no problems to get it to my shift_out function.

I hope I made it clear enough to understand, its kinda hard to explain  :smiley-roll-sweat:.

UKHeliBob

To clarify.  You want to pass the name of an array to a function ?
It sounds like passing a pointer would do what you want
http://arduino.cc/forum/index.php?topic=104626.0
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

WonderTiger

#2
Mar 05, 2013, 10:08 pm Last Edit: Mar 05, 2013, 10:11 pm by WonderTiger Reason: 1
In the function 'shift_out' I want 'animation' to be changed in like Array1[a][b ] or Array2[a][b ]. So the code will look something like this:

Code: [Select]

void shift_out(){
for(int a=0; a<5; a++){
     digitalWrite(latchPin, LOW);
     for(int b=0; b<6; b++){
       shiftOut(dataPin, clockPin, MSBFIRST, Array1[a][b]); <---------------------------
     }
     digitalWrite(latchPin, HIGH);
     delay(1);
   }
}

UKHeliBob

That's what I thought I suggested
Have you had a look at the link I gave ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

WonderTiger

Yes yes :D, I'm still trying to figure it out with the link you gave me. I just answered the question to make sure you understand what I'm trying to do  :P

Go Up