Problem with  digitalPinToPort  function

I’m trying to write a library and use the digitalPinToPort function found in the pinMode function. The compiler throws errors like

/Applications/DevelopmentApps/arduino-0011/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:266: error: expected unqualified-id before 'int'

/Applications/DevelopmentApps/arduino-0011/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:266: error: expected `)' before 'int'

/Applications/DevelopmentApps/arduino-0011/hardware/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/include/stdio.h:266: error: expected `)' before 'int'

#include “wiring_private.h”
#include “pins_arduino.h”
#include “avr/io.h”
#include “stdio.h”

int i;
unsigned int x, y;
float accum, fout; // these are variables for a simple low-pass (smoothing) filter
float fval = .07; // fval of 1 = no filter - .0001 = max filter

void setup() {

void loop() { }

int capSense(int pin){ // pin is the output (sending) pin. pin + 1 is the receiving pin.


#include “wiring_private.h”
#include “pins_arduino.h”

void pinMode(uint8_t pin, uint8_t mode) // code for pinMode
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *reg;

if (port == NOT_A_PIN) return;

// JWS: can I let the optimizer do this?
reg = portModeRegister(port);

if (mode == INPUT) *reg &= ~bit;
else *reg |= bit;


uint8_t sBit = digitalPinToBitMask(pin); // get bitmask for send pin - from the pinMode function
uint8_t rBit = digitalPinToBitMask(pin + 1); // get bitmask for receive pin

uint8_t sPort = digitalPinToPort(pin); // get port for send pin - from the pinMode function
uint8_t rPort = digitalPinToPort(pin + 1); // get port for receive pin

if (pin < 2 || pin > 12) return 0; // bail out if pin is out of range


I imagine I have an issue with some header that needs to be referenced. Any pointers would be appreciated.


This was a problem with a clash of a define introduced with the latest Arduino release and stdio.h .
You can work around it by placing:

#undef int()

before the:

#include <stdio.h>

Thanks mem - worked like a charm after I moved it above all my includes