Framework (A-Z)

Reference for Wiring version 1.0 Build 0100+ If you have a previous version, use the reference included with your software. If see any errors or have any comments, let us know.

Name

shiftIn()

Examples
int data = 0;    // Wiring pin 0 for data 
int clock = 1;   // Wiring pin 1 for clock 
int strobe = 2;  // Wiring pin 2 for the strobe (latch) 
int value = 0;

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

void loop() { 
  // pulse the strobe or latch pin on the shift register
  digitalWrite(strobe, LOW);  
  // reads 8 bits (one byte) of data from the register
  value = shiftIn(data, clock, LSBFIRST, 8);   
  digitalWrite(strobe, HIGH); 
  Serial.println(value);
  delay(1000);
}
Description The shiftIn() method reads data one bit at a time. It can start from the most or the least significant bit (starts from leftmost or rightmost bit). This method is very useful to manage shift registers (like CD4021), which are devices that convert data from parallel to serial using one Wiring pin for receiving data, one for the clock, and one for the strobe (latch).
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 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
Related shiftOut()
MSBFIRST
LSBFIRST
Updated on July 07, 2011 11:08:58pm PDT

Creative Commons License