Skip to content

Instantly share code, notes, and snippets.

@theapi
Created February 2, 2014 12:00
Show Gist options
  • Save theapi/8767363 to your computer and use it in GitHub Desktop.
Save theapi/8767363 to your computer and use it in GitHub Desktop.
/*
Shift Register Example
for 74HC595 shift register
*/
//Pin connected to latch pin (ST_CP) of 74HC595
const int latchPin = 13;
//Pin connected to clock pin (SH_CP) of 74HC595
const int clockPin = 12;
////Pin connected to Data in (DS) of 74HC595
const int dataPin = 11;
byte anodes = 0b10000000;
void setup() {
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop() {
digitalWrite(latchPin, LOW);
// Cathode 0 = ON, 1 = OFF
// RGB RGB RG
shiftOut(dataPin, clockPin, LSBFIRST, 0b01101111);
anodes >>= 1;
if (anodes == 0) {
anodes = 0b10000000;
}
// anodes: 1 = ON, 0 = OFF
shiftOut(dataPin, clockPin, LSBFIRST, anodes);
digitalWrite(latchPin, HIGH);
delay(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment