Pages: [1]   Go Down
Author Topic: trouble with void function.  (Read 653 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 1
Posts: 60
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
« Last Edit: March 05, 2013, 03:33:04 pm by WonderTiger » Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 114
Posts: 4267
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Jr. Member
**
Karma: 1
Posts: 60
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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);
    }
}
« Last Edit: March 05, 2013, 04:11:32 pm by WonderTiger » Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 114
Posts: 4267
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's what I thought I suggested
Have you had a look at the link I gave ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Jr. Member
**
Karma: 1
Posts: 60
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes yes smiley-grin, 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  smiley-razz
Logged

Offline Offline
Jr. Member
**
Karma: 1
Posts: 60
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Though I still can't get it working... I don't know exactly what i'm doing. Maybe can you give me a push in the right direction and make a start in my code I posted? Right now I'm doing it wrong...
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 114
Posts: 4267
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have a look at this.  It may give you a push in the right direction
Code:
byte Array1[3][2] =
{
  {1,2},
  {3,4},
  {5,6}
};

byte Array2[3][2] =
{
  {11,22},
  {33,44},
  {55,66}
};

void setup()
{
  Serial.begin(9600);
  showArray(Array1);
  Serial.println();
  showArray(Array2); 
}

void loop()
{
}

void showArray(byte passedArray[3][2])
{
  for (byte row =0;row < 3;row++)
  {
    for (byte col =0;col < 2;col++)
    {
      Serial.println(passedArray[row][col]);
    } 
  }
}
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Jr. Member
**
Karma: 1
Posts: 60
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you very much! Got it working now smiley. Now I also understand what they are doing in the link you posted! Thanks again!
Logged

Pages: [1]   Go Up
Jump to: