shiftOut()

Description

Shifts out a byte of data one bit at a time. Starts from either the most (i.e. the leftmost) or least (rightmost) significant bit. Each bit is written in turn to a data pin, after which a clock pin is pulsed (taken high, then low) to indicate that the bit is available.

Note: if you're interfacing with a device that's clocked by rising edges, you'll need to make sure that the clock pin is low before the call to shiftOut(), e.g. with a call to digitalWrite(clockPin, LOW).

This is a software implementation; see also the SPI library, which provides a hardware implementation that is faster but works only on specific pins.

Syntax

shiftOut(dataPin, clockPin, bitOrder, value)

Parameters

dataPin: the pin on which to output each bit (int)

clockPin: the pin to toggle once the dataPin has been set to the correct value (int)

bitOrder: which order to shift out the bits; either MSBFIRST or LSBFIRST.(Most Significant Bit First, or, Least Significant Bit First)

value: the data to shift out. (byte)

Returns

None

Note

The dataPin and clockPin must already be configured as outputs by a call to pinMode().

shiftOut is currently written to output 1 byte (8 bits) so it requires a two step operation to output values larger than 255.

voidsetup(){//set pins to output because they are addressed in the main looppinMode(latchPin,OUTPUT);pinMode(clockPin,OUTPUT);pinMode(dataPin,OUTPUT);}

voidloop(){//count up routinefor(int j =0; j <256; j++){//ground latchPin and hold low for as long as you are transmittingdigitalWrite(latchPin,LOW);shiftOut(dataPin, clockPin,LSBFIRST, j);//return the latch pin high to signal chip that it //no longer needs to listen for informationdigitalWrite(latchPin,HIGH);delay(1000);}}