Port shift()

This can be used to send out a pulse sequence of bits or to read such a pulse sequence in. The AIO line is cycled while the value bits are "shifted" and written out to (shift, shiftWrite) or read in from (shiftRead) the DIO pin.

The shiftWrite() call is similar but more general than the shift() call in that it allows an adjustable number of bits to be sent out, not just 8.

#include <Ports.h> 
#include <RF12.h> // needed to avoid a linker error :(

Port port (1);
void port.shift(byte bitOrder, byte value);
void port.shiftWrite(byte bitOrder, word value);
void port.shiftWrite(byte bitOrder, word value, byte count);
word port.shiftRead(byte bitOrder);
word port.shiftRead(byte bitOrder, byte count);

Parameters

bitOrder

How to shift bits in or out: either LSBFIRST (0) or MSBFIRST (1), where LSB stands for Least Significant Bit and MSB for Most Significant Bit.

value

The value to shift out, with as many lower bits as needed. This argument is a byte for shift() and a word for the more general shiftWrite() function.

count

The number of bits to shift in or out. Must be in the range 1 .. 16, the default is 8.

Notes

The correct I/O direction of the DIO and AIO pins has to be set up with Port mode() calls before using these functions.

The shift() call is a thin wrapper around the Arduino shiftOut() function.