Skip to content

Instantly share code, notes, and snippets.

@giljr
Created May 14, 2017 17:44
Show Gist options
  • Save giljr/9e697a42be1b779f497ca4d0db94d463 to your computer and use it in GitHub Desktop.
Save giljr/9e697a42be1b779f497ca4d0db94d463 to your computer and use it in GitHub Desktop.
How Shift Register Works? page: https://goo.gl/GcZxCR
const int clockPin = 9; //Clock sequence
const int dataPin = 8; //Serial data line
const int latchPin = 10; //Latch Pin
void setup(){
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(latchPin, OUTPUT);
}
void loop(){
for(int i = 0; i<8; i++)
{
shiftOut(dataPin, clockPin, MSBFIRST, B00000001 << i);
digitalWrite(latchPin, HIGH);
delay(200);//125*8 = 1 second
digitalWrite(latchPin, LOW);
}
for (int j = 0; j<8; j++)
{
shiftOut(dataPin, clockPin, MSBFIRST, B10000000 >> j);
digitalWrite(latchPin, HIGH);
delay(200);//125*8 = 1 second
digitalWrite(latchPin, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment