Arduino Programming Language: ShiftOut

Name

shiftOut()

Description

The shiftOut() function writes data on a pin, one bit at a time. 
It can write bits starting from the most or the least significant bit (leftmost or rightmost bit).

Syntax

shiftOut(dataPin,clockPin,bitOrder,data);
shiftOut(dataPin,clockPin,bitOrder,data,count);
shiftOut(dataPin,clockPin,bitOrder,data,count,delayTime);

Parameters

  • dataPin

int: the pin used to send out the data

  • clockPin

int: the pin used as clock

  • bitOrder

MSBFIRST or LSBFIRST: the bit order to use. MSBFIRST stands for most significant bit first (leftmost bit), LSBFIRST stands for less significant bit first (rightmost bit).

  • data

byte or unsigned int: the data to send out. If no count specified a byte (8 bits) is assumed

  • count

count: the number of bits to send (1 to 16).

  • delayTime (optional parameter)

delay in milliseconds for internally generate the clock pulse in the clockPin pin. This is useful for configuring the speed at which the shift register or a device can handle a new bit of a data.

Returns

none 

Usage

Application

Examples

int data = 0; // PIN for data
int clock = 1; // PIN for clock
int strobe = 2; // PIN for latch
byte value = 0;

void setup() {
pinMode(data, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(strobe, OUTPUT);
}

void loop() {
// pulse the latch pin on the shift register
digitalWrite(strobe, LOW);
// writes 'value' to the register
shiftOut(data, clock, LSBFIRST, value);
digitalWrite(strobe, HIGH);
delay(1000);
value = value + 1;
}

Related Functions


Based on the reference originally written by Arduino Community,  wiring.org.co and  arduino.cc