Arduino Programming Language: ShiftIn

Name

shiftIn()

Description

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

Syntax

shiftIn(dataPin,clockPin,bitOrder);
shiftIn(dataPin,clockPin,bitOrder,count);
shiftIn(dataPin,clockPin,bitOrder,count, delayTime);

Parameters

  • dataPin

int: the pin used to receive 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).

  • count

count: the number of bits to read (1 to 16). If no count is specified 8 (the size of a byte) is assumed

  • 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 read and provide a new bit of a data.

Returns

int: the data read from the pin 

Usage

Application

Examples

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

void setup() {
pinMode(data INPUT);
pinMode(clock, OUTPUT);
// latch or latch pin ona a shift register
pinMode(latch, OUTPUT);
Serial.begin(9600);
}

void loop() {
// pulse the latch or latch pin on the shift register
digitalWrite(latch, LOW);
// reads 8 bits (one byte) of data from the register
value = shiftIn(data, clock, LSBFIRST, 8);
digitalWrite(latch, HIGH);
Serial.println(value);
delay(1000);
}

Related Functions


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