//Random blinking LEDS using a 74HC595 shift register. Original code found on bildr.org

int SER_Pin = 11; //pin 15 on the 75HC595
int RCLK_Pin = 8; //pin 12 on the 75HC595
int SRCLK_Pin = 12; //pin 10 on the 75HC595

int Array [29] = {
0b00000001,
0b00000011,
0b00000111,
0b00001111,
0b00011111,
0b00111111,
0b01111111,
0b11111111,
0b01000000,
0b00100000,
0b00010000,
0b00001000,
0b00000010,
0b00001000,
0b00010000,
0b00100000,
0b10000000,
0b01000000,
0b00100000,
0b00010000,
0b00000000,
0b11111111,
0b00000000,
0b11111111,
0b00000000,
0b11111111,
0b00000000,
0b11111111
};

#define number_of_74hc595s 1 //How many of the shift registers are there daisey chained?
#define numOfRegisters number_of_74hc595s * 9

int registers[numOfRegisters];

void setup(){

Serial.begin(9600);
setRegister(1, LOW);
setRegister(2, LOW);
setRegister(3, LOW);
setRegister(4, LOW);
setRegister(5, LOW);
setRegister(6, LOW);
setRegister(7, LOW);
setRegister(8, LOW);

writeRegisters();

pinMode(SER_Pin, OUTPUT);
pinMode(RCLK_Pin, OUTPUT);
pinMode(SRCLK_Pin, OUTPUT);
randomSeed(analogRead(A0));

clearRegisters();
writeRegisters();
}

void clearRegisters(){
//set all registers to LOW
for(int i = numOfRegisters; i > 0; i–){
registers[i] = LOW;
}
}

void writeRegisters(){
//Set and display registers
digitalWrite(RCLK_Pin, LOW);

for(int i = numOfRegisters; i > 0; i–){
digitalWrite(SRCLK_Pin, LOW);

int val = registers[i];

digitalWrite(SER_Pin, val);
digitalWrite(SRCLK_Pin, HIGH);
}
digitalWrite(RCLK_Pin, HIGH);
}

void setRegister(int index, int value){
//set individual register
registers[index] = value;
}

void loop(){
clearRegisters();

for(int i= 0; i < numOfRegisters; i ++){
int randNum = random(2);

if(randNum == 1){
setRegister(i, HIGH);
}
}

writeRegisters();
delay(333);
}

 


We hope that you found the information in this page useful. The internet is all about getting and giving. And giving back is the best. Please donate $1 or more to aid us in our continuing quest to add to and polish the information in our site.


Scroll to top