Input/Output
digitalWrite()
Write a HIGH
or a LOW
value to a GPIO pin.
// PROTOTYPE
void digitalWrite(uint16_t pin, uint8_t value)
If the pin has been configured as an OUTPUT
with pinMode()
or if previously used with analogWrite()
, its voltage will be set to the corresponding value: 3.3V for HIGH, 0V (ground) for LOW.
digitalWrite()
takes two arguments, pin
: the number of the pin whose value you wish to set and value
: HIGH
or LOW
.
digitalWrite()
does not return anything.
// EXAMPLE USAGE
int LED = D1; // LED connected to D1
void setup()
{
pinMode(LED, OUTPUT); // sets pin as output
}
void loop()
{
digitalWrite(LED, HIGH); // sets the LED on
delay(200); // waits for 200mS
digitalWrite(LED, LOW); // sets the LED off
delay(200); // waits for 200mS
}
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 output as long they are not used otherwise (e.g. asSerial1
RX
/TX
).For the B-Series SoM all GPIO pins (
A0
..A7
,D0
..D13
,D22
,D23
) can be used for digital output 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 output 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.The default drive strength on Gen 3 devices is 2 mA per pin. This can be changed to 9 mA using
pinSetDriveStrength()
.
Gen 4 Devices (RTL872x) (P2, Photon 2, and M-SoM):
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
).Pins
D0
andD1
can be used as analog inputs on the P2 (A3
andA4
) if I2C is not being used.The drive strength on the M-SoM, P2, and Photon 2 is 4 mA per pin in normal drive and 12 mA per pin in high drive mode. Drive strength selection is only available in Device OS 5.5.0 and later. There is a maximum of 200 mA across all pins. On the P2, the total maximum could be further limited by your 3.3V regulator.
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
). For the Electron and SeriesB0
..B5
,C0
..C5
can be used as well.The drive current on Gen 2 devices is 25 mA per pin, with a maximum of 125 mA across all GPIO.