Skip to content

Instantly share code, notes, and snippets.

@hezhao
Last active December 19, 2015 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hezhao/5963568 to your computer and use it in GitHub Desktop.
Save hezhao/5963568 to your computer and use it in GitHub Desktop.
// See http://bildr.org/2011/02/74hc595/
int SER_Pin = 11; //pin 14 (Data) on the 75HC595
int RCLK_Pin = 9; //pin 12 (Latch) on the 75HC595
int SRCLK_Pin = 8; //pin 11 (Clock) on the 75HC595
//How many of the shift registers - change this
#define number_of_74hc595s 8
//do not touch
#define numOfRegisterPins number_of_74hc595s * 8
boolean registers[numOfRegisterPins];
void setup()
{
pinMode(SER_Pin, OUTPUT);
pinMode(RCLK_Pin, OUTPUT);
pinMode(SRCLK_Pin, OUTPUT);
//reset all register pins
clearRegisters();
//writeRegisters();
}
//set all register pins to LOW
void clearRegisters(){
for(int i = numOfRegisterPins - 1; i >= 0; i--){
registers[i] = LOW;
}
}
//Set and display registers
//Only call AFTER all values are set how you would like (slow otherwise)
void writeRegisters(){
digitalWrite(RCLK_Pin, LOW);
for(int i = numOfRegisterPins - 1; i >= 0; i--){
digitalWrite(SRCLK_Pin, LOW);
int val = registers[i];
digitalWrite(SER_Pin, val);
digitalWrite(SRCLK_Pin, HIGH);
}
digitalWrite(RCLK_Pin, HIGH);
}
//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
registers[index] = value;
}
void setRegisters(int regs[])
{
for (int i=0; i < numOfRegisterPins; i++)
{
registers[i] = regs[i];
}
}
void loop()
{
// setRegisterPin(1, LOW);
int regs[] = {
1,1,1,1,1,1,1,1,
1,0,0,0,0,0,0,0,
1,0,0,0,0,0,0,0,
1,0,0,0,0,0,0,0,
1,0,0,0,0,0,0,0,
1,0,0,0,0,0,0,0,
1,0,0,0,0,0,0,0,
1,0,0,0,0,0,0,0};
setRegisters(regs);
writeRegisters(); //MUST BE CALLED TO DISPLAY CHANGES
//Only call once after the values are set how you need.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment