Making a local variable global?

I am trying to multiplex some seven segments(common cathode), and I want to write my own code. I am using functions in order to more easily change what the program is doing later on. The first simple function defines the pins used for the LED's and sets them as outputs (I would think). I did this so I could change these easily later on. I want to use the pin assignments in other parts of the code, but still define them as arguments in the multiplexPins function. Is there any way to do this? (In general, I need to know how to do the title of this thread.)

This is what I am using for the first function.

void multiplexPins(const int pinA, const int pinB, const int pinC, const int pinD, int pinE, const int pinF, const int pinG, const int blinkPin){
  pinMode(pinA, OUTPUT);
  pinMode(pinB, OUTPUT);
  pinMode(pinC, OUTPUT);
  pinMode(pinD, OUTPUT);
  pinMode(pinE, OUTPUT);
  pinMode(pinF, OUTPUT);
  pinMode(pinG, OUTPUT);
  pinMode(blinkPin, OUTPUT);
}

Keep in mind, I'm very new to arduino. Sorry if what I'm saying isn't exactly clear. Thanks :slight_smile:

EDIT: I may have a solution, but I am not sure if it works. I added this to the code.

int pinA = 0;
int pinB = 0;
int pinC = 0;
int pinD = 0;
int pinE = 0;
int pinF = 0;
int pinG = 0;
int blinkPin = 3;
void multiplexPins(const int pinA, const int pinB, const int pinC, const int pinD, int pinE, const int pinF, const int pinG, const int blinkPin){
  pinMode(pinA, OUTPUT);
  pinMode(pinB, OUTPUT);
  pinMode(pinC, OUTPUT);
  pinMode(pinD, OUTPUT);
  pinMode(pinE, OUTPUT);
  pinMode(pinF, OUTPUT);
  pinMode(pinG, OUTPUT);
  pinMode(blinkPin, OUTPUT);
}

First, I would use an array, rather than 8 individual variables.

Second, you could make the array (or variables) global, however assign them in your function. eg.

byte pins [8];   // no values yet (defaults to zero)

void multiplexPins (byte myPins [8])
  {
  for (int i = 0; i < 8; i++)
    {
    pins [i] = myPins [i];
    pinMode (pins [i], OUTPUT);
    }
  }  // end of multiplexPins

void setup ()
  {
  byte wantedPins [8] = { 8, 5, 4, 2, 1, 3, 6, 9 };
  multiplexPins (wantedPins);
  }  // end of setup

void loop ()
  {
  // whatever 
  }  // end of loop

I'm not sure what that really achieves over defining the pins globally in the first place.

It is probably very unwise to go messing with pin 0 or pin 1.

an easy but not perfect way is to use an array to pass the parameters, so the size can be changed easily.

See: http://www.arduino.cc/en/Reference/Array

and use

const int MY_SIZE = 7;
int myarray[MY_SIZE] = {pinA, pinB, ....};

void loop()
{
    multiplexPins(myarray, MY_SIZE);
}

void multiplexPins(int array[], int size)
{
...
}