Pullup configuration

General support questions and discussions.

Pullup configuration

Postby tvillingett » Mon Dec 16, 2013 5:59 pm

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
tvillingett
 
Posts: 2
Joined: Mon Dec 16, 2013 4:43 pm

Re: Pullup configuration

Postby support » Tue Dec 17, 2013 9:18 pm

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,
support
Site Admin
 
Posts: 384
Joined: Thu Aug 22, 2013 7:30 pm


Return to Support



cron