
The PortIn interface is used to read an underlying GPIO port as one value. This is much faster than BusIn as you can read a port in one go, but much less flexible as 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.
// 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;
}
}
}
| PortIn | A multiple pin digital input |
| Functions | |
| PortIn | Create an PortIn, connected to the specified port |
| read | Read the value currently output on the port |
| mode | Set the input pin mode |
| operator int() | A shorthand for read |
A multiple pin digital input
class PortIn
Create an PortIn, connected to the specified port
PortIn( PortName port, int mask = 0xFFFFFFFF )
Read the value currently output on the port
int read()
Set the input pin mode
void mode( PinMode mode )
A shorthand for read
operator int()
No tags
|
8 comments
Please login to post comments.
In the above example, how do you know port2 is a group of P21-P26 ?