Mbed OS Reference
Loading...
Searching...
No Matches
PortIn Class Reference

A multiple pin digital input. More...

#include <PortIn.h>

Public Member Functions

 PortIn (PortName port, int mask=0xFFFFFFFF)
 Create a PortIn, connected to the specified port. More...
 
int read ()
 Read the value input to the port. More...
 
void mode (PinMode mode)
 Set the input pin mode. More...
 
 operator int ()
 A shorthand for read() More...
 

Detailed Description

A multiple pin digital input.

Note
Synchronization level: Interrupt safe

Example:

// Turn on an LED if any pins of Port2[0:5] are high
#include "mbed.h"
PortIn p(Port2, 0x0000003F); // Port2 pins [0:5] only
DigitalOut led(LED4);
int main() {
while(1) {
int pins = p.read();
if(pins) {
led = 1;
} else {
led = 0;
}
}
}
A digital output, used for setting the state of a pin.
Definition: DigitalOut.h:55
A multiple pin digital input.
Definition: PortIn.h:58

Definition at line 58 of file PortIn.h.

Constructor & Destructor Documentation

◆ PortIn()

PortIn ( PortName  port,
int  mask = 0xFFFFFFFF 
)

Create a PortIn, connected to the specified port.

Parameters
portPort to connect to (as defined in target's PortNames.h)
maskBitmask defines which port pins should be an input (0 - ignore, 1 - include)

Member Function Documentation

◆ read()

int read ( )

Read the value input to the port.

Returns
An integer with each bit corresponding to the associated pin value

Definition at line 73 of file PortIn.h.

◆ mode()

void mode ( PinMode  mode)

Set the input pin mode.

Parameters
modePullUp, PullDown, PullNone, OpenDrain

◆ operator int()

operator int ( )

A shorthand for read()

Definition at line 86 of file PortIn.h.