Input/Output
digitalRead()
Reads the value from a specified digital pin
, either HIGH
or LOW
.
// PROTOTYPE
int32_t digitalRead(uint16_t pin)
digitalRead()
takes one argument, pin
: the number of the digital pin you want to read.
digitalRead()
returns HIGH
or LOW
.
// EXAMPLE USAGE
int button = D0; // button is connected to D0
int LED = D1; // LED is connected to D1
int val = 0; // variable to store the read value
void setup()
{
pinMode(LED, OUTPUT); // sets pin as output
pinMode(button, INPUT_PULLDOWN); // sets pin as input
}
void loop()
{
val = digitalRead(button); // read the input pin
digitalWrite(LED, val); // sets the LED to the button's value
}
Gen 3 Devices (nRF52) (B-Series SoM, Tracker SoM, Tracker One, Boron, Argon, and E404X):
For all Feather Gen 3 devices (Argon, Boron, Xenon) all GPIO pins (
A0
..A5
,D0
..D13
) can be used for digital input as long they are not used otherwise (e.g. asSerial1
RX
/TX
).For the Boron SoM all GPIO pins (
A0
..A7
,D0
..D13
,D22
,D23
) can be used for digital input as long they are not used otherwise (e.g. asSerial1
RX
/TX
).For the Tracker SoM all GPIO pins (
A0
..A7
,D0
..D9
) can be used for digital input as long they are not used otherwise (e.g. asSerial1
RX
/TX
). Note that on the Tracker SoM pins A0 - A7 and the same physical pins as D0 - D7 and are just alternate names for the same pins.GPIO are not 5V tolerant on Gen 3 devices. Be sure the input voltage does not exceed 3.3V (typical) or 3.6V (absolute maximum).
P2 and Photon 2 Devices (RTL872x):
All GPIO pins (
A0
,A1
,A2
,A5
,D0
..D10
,MOSI
,MISO
,SCK
,RX
,TX
) can be used as long they are not used otherwise (e.g. asSerial1
RX
/TX
).GPIO are not 5V tolerant on the P2 and Photon 2. Be sure the input voltage does not exceed 3.3V (typical).
For the P2 and Photon pin, if you are using an external pull-down resistor, the resistance m be greater than or equal to 1K. It is typically larger than that, but it cannot be smaller.
Gen 2 Devices (STM32) (E-Series, Electron, Photon, and P2; does not include E404X):
- All GPIO pins (
A0
..A7
,D0
..D7
,DAC
,WKP
,RX
,TX
) can be used as long they are not used otherwise (e.g. asSerial1
RX
/TX
). On the Electron and E-Series, there are additional GPIOB0
..B5
,C0
..C5
as well. - On the Photon, Electron, and E-Series, all GPIO pins except A3 and A6 are 5V tolerant. However you must not use
INPUT_PULLUP
orINPUT_PULLDOWN
with 5V inputs. - On the P1, all GPIO pins except A3, A6, D0 and D1 are 5V tolerant. However you must not use
INPUT_PULLUP
orINPUT_PULLDOWN
with 5V inputs. - On the P1 there are 2.1K hardware pull-up resistors to 3V3 on D0 and D1 and are not 5V tolerant.