Skip to content

Commit 76c964d

Browse files
committed
Adding INPUT_PULLUP option pinMode(). (Paul Stoffregen).
This also changes pinMode(pin, INPUT); to explicitly disable the pull-up resistor, even if it was previously set. http://code.google.com/p/arduino/issues/detail?id=246
1 parent 5088b09 commit 76c964d

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

build/shared/lib/keywords.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
HIGH LITERAL1 Constants
44
LOW LITERAL1 Constants
55
INPUT LITERAL1 Constants
6+
INPUT_PULLUP LITERAL1 Constants
67
OUTPUT LITERAL1 Constants
78
DEC LITERAL1 Serial_Print
89
BIN LITERAL1 Serial_Print

hardware/arduino/cores/arduino/Arduino.h

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extern "C"{
2020

2121
#define INPUT 0x0
2222
#define OUTPUT 0x1
23+
#define INPUT_PULLUP 0x2
2324

2425
#define true 0x1
2526
#define false 0x0

hardware/arduino/cores/arduino/wiring_digital.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,25 @@ void pinMode(uint8_t pin, uint8_t mode)
3232
{
3333
uint8_t bit = digitalPinToBitMask(pin);
3434
uint8_t port = digitalPinToPort(pin);
35-
volatile uint8_t *reg;
35+
volatile uint8_t *reg, *out;
3636

3737
if (port == NOT_A_PIN) return;
3838

3939
// JWS: can I let the optimizer do this?
4040
reg = portModeRegister(port);
41+
out = portOutputRegister(port);
4142

4243
if (mode == INPUT) {
4344
uint8_t oldSREG = SREG;
4445
cli();
4546
*reg &= ~bit;
47+
*out &= ~bit;
48+
SREG = oldSREG;
49+
} else if (mode == INPUT_PULLUP) {
50+
uint8_t oldSREG = SREG;
51+
cli();
52+
*reg &= ~bit;
53+
*out |= bit;
4654
SREG = oldSREG;
4755
} else {
4856
uint8_t oldSREG = SREG;

0 commit comments

Comments
 (0)