Skip to content

Instantly share code, notes, and snippets.

@elktros
Created September 14, 2018 06:42
Show Gist options
  • Save elktros/7accb234a28b5f12a68db27091a57992 to your computer and use it in GitHub Desktop.
Save elktros/7accb234a28b5f12a68db27091a57992 to your computer and use it in GitHub Desktop.
Code for Interfacing 74HC595 Shift Register with Arduino.
int latchPin = 5;
int clkPin = 6;
int dataPin = 4;
byte LED = 0;
void setup()
{
Serial.begin(9600);
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clkPin, OUTPUT);
}
void loop()
{
int i=0;
LED = 0;
shiftLED();
delay(500);
for (i = 0; i < 8; i++)
{
bitSet(LED, i);
Serial.println(LED);
shiftLED();
delay(500);
}
}
void shiftLED()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clkPin, MSBFIRST, LED);
digitalWrite(latchPin, HIGH);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment