user25944: My task is to use a port extender (MCP23s17) to drive a touch keypad for which I have to define names of pins so that I can call those names in arguments of a function.
I have searched for different methods to define "PORT EXTENDER" pin but could not find any satisfactory results. Kindly help me handle the situation.
i have used the following libraries downloaded from Arduino playground
1. CapacitiveSensor.h
2. MCP23S17.h
Now I have to use MCP23S17 Pin in the following function
#define key1 2
#define key2 4
CapacitiveSensor cs_4_2=Capacitivesensor(key2,key1);  //capacitive sensor is connected to pin 4 and 2

key1 and key2 are Arduino's pins. I want some method by which I can refer key1 and key2 to the port extender's (MSP23S17) pin. The above answers are surely helpful but they doesn't fulfill my requirement.
Thanks in Advance
Sorry for English.

user2881: If you use this arduino library:
#define LED_PIN 15

mcp.pinMode(LED_PIN, LOW); //set led pin on the MCP23S17 to an OUTPUT

mcp.digitalWrite(LED_PIN, LOW)


user4143: If you are using my library you can do something like:
MCP23S17 expander1(&SPI, 10);

#define LED_PIN expander1, 15

void setPin(MCP23S17 &expander, int pin, bool level) {
    expander.digitalWrite(pin, level);
}

// ... later ...

setPin(LED_PIN, HIGH);


user23966: There is also the Adafruit Library, all do similar things, just in a slightly different way. I use this one, it just depends on which method you are most comfortable with and what your requirements are. Try them all and find out. 
void setup() {
  Serial.begin(9600);  // debugging  
  mcp.begin();      // use default address 0

      for(int i = 0; i < 6; i++) {
        mcp.pinMode(trafficLights1[i], OUTPUT);
      }
       for(int i = 0; i < 6; i++) { 
        mcp.pinMode(trafficLights2[i], OUTPUT);
       }
        for(int i = 0; i < 5; i++) {
        mcp.pinMode(trafficLights3[i], OUTPUT);
        }
  for (int P=0;P<16;P++) {
    mcp.pullUp(P, HIGH);  // turn on a 100K pullup internally
    mcp.digitalWrite(P,LOW);
 }
      mcp.digitalWrite(11, HIGH);
}


25944: <p>My task is to use a port extender (MCP23s17) to drive a touch keypad for which I have to define names of pins so that I can call those names in arguments of a function.</p>

<p>I have searched for different methods to define "PORT EXTENDER" pin but could not find any satisfactory results. Kindly help me handle the situation.</p>

<p>i have used the following libraries downloaded from Arduino playground
1. CapacitiveSensor.h
2. MCP23S17.h
Now I have to use MCP23S17 Pin in the following function</p>

<pre><code>#define key1 2
#define key2 4
CapacitiveSensor cs_4_2=Capacitivesensor(key2,key1);  //capacitive sensor is connected to pin 4 and 2
</code></pre>

<p>key1 and key2 are Arduino's pins. I want some method by which I can refer key1 and key2 to the port extender's (MSP23S17) pin. The above answers are surely helpful but they doesn't fulfill my requirement.</p>

<p>Thanks in Advance
Sorry for English.</p>
 2881: <p>If you use this <a href="http://playground.arduino.cc/Main/MCP23S17#pinMode" rel="nofollow">arduino library</a>:</p>

<pre><code>#define LED_PIN 15

mcp.pinMode(LED_PIN, LOW); //set led pin on the MCP23S17 to an OUTPUT

mcp.digitalWrite(LED_PIN, LOW)
</code></pre>
 4143: <p>If you are using <a href="https://github.com/MajenkoLibraries/MCP23S17" rel="nofollow">my library</a> you can do something like:</p>

<pre><code>MCP23S17 expander1(&amp;SPI, 10);

#define LED_PIN expander1, 15

void setPin(MCP23S17 &amp;expander, int pin, bool level) {
    expander.digitalWrite(pin, level);
}

// ... later ...

setPin(LED_PIN, HIGH);
</code></pre>
 23966: <p>There is also the <a href="https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library" rel="nofollow">Adafruit</a> Library, all do similar things, just in a slightly different way. I use this one, it just depends on which method you are most comfortable with and what your requirements are. Try them all and find out. </p>

<pre><code>void setup() {
  Serial.begin(9600);  // debugging  
  mcp.begin();      // use default address 0

      for(int i = 0; i &lt; 6; i++) {
        mcp.pinMode(trafficLights1[i], OUTPUT);
      }
       for(int i = 0; i &lt; 6; i++) { 
        mcp.pinMode(trafficLights2[i], OUTPUT);
       }
        for(int i = 0; i &lt; 5; i++) {
        mcp.pinMode(trafficLights3[i], OUTPUT);
        }
  for (int P=0;P&lt;16;P++) {
    mcp.pullUp(P, HIGH);  // turn on a 100K pullup internally
    mcp.digitalWrite(P,LOW);
 }
      mcp.digitalWrite(11, HIGH);
}
</code></pre>
