const byte
dataPin = 2,
clockPin = 3,
latchPin = 4,
numBits = 8
;
void setup ()
{
Serial.begin ( 115200 );
pinMode ( dataPin, INPUT );
pinMode ( clockPin, OUTPUT );
pinMode ( latchPin, OUTPUT );
}
void loop ()
{
digitalWrite ( latchPin, LOW );
digitalWrite ( latchPin, HIGH );
Serial.print ( "Bits: " );
for ( byte n = 0; n < numBits; n ++ )
{
Serial.print ( digitalRead ( dataPin ) );
digitalWrite ( clockPin, HIGH ); // Shift out the next bit
digitalWrite ( clockPin, LOW );
}
Serial.println ();
delay ( 200 );
}