PortOut

Use the PortOut class to write to an underlying GPIO port as one value. This is much faster than BusOut because you can write 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 classes.

API

Public Member Functions

 PortOut (PortName port, int mask=0xFFFFFFFF)
void write (int value)
int read ()
PortOutoperator= (int value)
PortOutoperator= (PortOut &rhs)
 operator int ()

Hello World!

 


#include "mbed.h"

PwmOut led(LED1);

int main() {
    // specify period first
    led.period(4.0f);      // 4 second period
    led.write(0.50f);      // 50% duty cycle, relative to period
    //led = 0.5f;          // shorthand for led.write()
    //led.pulsewidth(2);   // alternative to led.write, set duty cycle time in seconds
    while(1);
}