Mistake on this page?
Report an issue in GitHub or email us


Use the PortIn interface to read an underlying GPIO port as one value. This is much faster than BusIn because you can read a port in one go, but it is much less flexible because you are constrained by the port and bit layout of the underlying GPIO ports.

A mask can be supplied so only certain bits of a port are used, allowing other bits to be used for other interfaces.

PortIn class reference

Public Member Functions
 PortIn (PortName port, int mask=0xFFFFFFFF)
int read ()
void mode (PinMode mode)
 operator int ()

PortIn hello, world

// Switch on an LED if any of mbed pins 21-26 is high
#include "mbed.h"
PortIn     p(Port2, 0x0000003F);   // p21-p26
DigitalOut ind(LED4);
int main() {
    while(1) {
        int pins = p.read();
        if(pins) {
            ind = 1;
        } else {
            ind = 0;
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.