Page 1 of 1

Pullup configuration

PostPosted: Mon Dec 16, 2013 5:59 pm
by tvillingett
When I tried to use a magnetic switch with built in pull-up, I had to change the code for the pull-up to work. I don't know if it is an old IDE to use +14 for pull-up?
I have earlier used PULLUP directly on the digital inputs, and it worked after removed "+14" these two places (the old code is commented).

Code: Select all
void configureStatusPin(int pinNumber)
{
  #if defined(STATUS_STRATEGY_3VCLOSED_5VOPENED) || defined(STATUS_STRATEGY_5VCLOSED_3VOPENED)
    pinMode(pinNumber, INPUT);
  #elif defined(STATUS_STRATEGY_NORMALLY_CLOSED) || defined(STATUS_STRATEGY_NORMALLY_OPENED)
    //pinMode(pinNumber+14, INPUT_PULLUP); // addressing analog pins as digital pins (+14)
    pinMode(pinNumber, INPUT_PULLUP); // addressing analog pins as digital pins (+14)
  #endif
}

//----------------------------------------------------------------------------------------------------
boolean isOpen(int pinNumber)
{
  #if defined(STATUS_STRATEGY_3VCLOSED_5VOPENED) || defined(STATUS_STRATEGY_5VCLOSED_3VOPENED)
    int status = analogRead(pinNumber);
  #elif defined(STATUS_STRATEGY_NORMALLY_CLOSED) || defined(STATUS_STRATEGY_NORMALLY_OPENED)
    //int status = digitalRead(pinNumber+14); // addressing analog pins as digital pins (+14)
    int status = digitalRead(pinNumber);
  #endif

Re: Pullup configuration

PostPosted: Tue Dec 17, 2013 9:18 pm
by support
Hi,

You'd typically do this to address an analog pin as a digital pin. If you don't do the +14,
you'd addressing those pins as regular analog pins instead of digital pins.

See following forum post for details: http://forum.arduino.cc/index.php?topic=28720.0

I guess it depends on what you're trying to do. If you want to address those pins using analog read,
you should instead change your STATUS STRATEGY to one of the ANALOG STRATEGY values:

STATUS_STRATEGY_3VCLOSED_5VOPENED
STATUS_STRATEGY_5VCLOSED_3VOPENED

When using one of the newer DIGITAL STRATEGY values ...

STATUS_STRATEGY_NORMALLY_CLOSED
STATUS_STRATEGY_NORMALLY_OPENED

... it is expected that you want to read the status using a digital 0/1 read.

Best regards,