Created
February 2, 2014 12:00
-
-
Save theapi/8767363 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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