Loading...
Searching...
No Matches
Digital I/O

pinMode(), digitalWrite(), digitalRead(). More...

Functions

uint8_t digitalPinToGpio (pin_size_t pin)
 RP2040 GPIO behind an Arduino pin, for use with the pico-sdk.
void pinMode (pin_size_t pinNumber, PinMode pinMode)
 Sets a pin as an input or an output.
void digitalWrite (pin_size_t pinNumber, PinStatus status)
 Sets an output pin HIGH (3.3 V) or LOW (0 V).
PinStatus digitalRead (pin_size_t pinNumber)
 Reads the level on a pin.

Detailed Description

pinMode(), digitalWrite(), digitalRead().

All pins are 3.3 V. A3-A5 are analog only: digital functions ignore them.

Function Documentation

◆ digitalPinToGpio()

uint8_t digitalPinToGpio ( pin_size_t pin)
inline

RP2040 GPIO behind an Arduino pin, for use with the pico-sdk.

Parameters
pinArduino pin number (e.g. 2, A0, LED_BUILTIN).
Returns
GPIO number, or NOT_A_GPIO for a pin with no GPIO behind it (A3-A5) or a pin number out of range.

◆ digitalRead()

PinStatus digitalRead ( pin_size_t pinNumber)

Reads the level on a pin.

Works in any mode, including OUTPUT (it reads back the pin). Inputs are HIGH above about 2 V and LOW below about 0.8 V.

Parameters
pinNumberArduino pin.
Returns
HIGH or LOW. Always LOW for A3-A5 and numbers out of range.
Note
After analogRead() on A0-A2, call pinMode() before digitalRead() on that pin: analogRead() turns off its digital input.
Examples
AnalogBurstBackground.ino, and FreeRtosTasks.ino.

◆ digitalWrite()

void digitalWrite ( pin_size_t pinNumber,
PinStatus status )

Sets an output pin HIGH (3.3 V) or LOW (0 V).

What it does depends on the pin's mode:

  • OUTPUT: drives the pin.
  • OUTPUT_OPENDRAIN: LOW drives the pin low, HIGH releases it.
  • INPUT: HIGH turns on the pull-up and LOW turns it off, as on an Uno.
Parameters
pinNumberArduino pin. A3-A5 and numbers out of range are ignored.
statusHIGH or LOW.
Note
Unlike an Uno, digitalWrite() does not stop analogWrite() or tone() output: call pinMode() first to use the pin as a plain output again.
Examples
AnalogBurstBackground.ino, CmsisRtos2Threads.ino, FreeRtosTasks.ino, MulticoreBasics.ino, and MulticoreFifo.ino.

◆ pinMode()

void pinMode ( pin_size_t pinNumber,
PinMode pinMode )

Sets a pin as an input or an output.

Also stops analogWrite() or tone() output on the pin and returns it to a plain digital pin.

Parameters
pinNumberArduino pin (e.g. 2, A0, LED_BUILTIN). A3-A5 and numbers out of range are ignored.
pinModeOne of:
  • INPUT: no pull resistor.
  • INPUT_PULLUP, INPUT_PULLDOWN: the RP2040's weak internal pull-up or pull-down.
  • OUTPUT: driven high or low.
  • OUTPUT_OPENDRAIN: driven low, or released (floating) for HIGH. Needs a pull-up resistor.
Warning
The pins are 3.3 V and not 5 V tolerant: do not connect a 5 V signal directly.
Examples
AnalogBurstBackground.ino, CmsisRtos2Threads.ino, FreeRtosTasks.ino, MulticoreBasics.ino, and MulticoreFifo.ino.