Blinking 8 LEDs with Shift Register (74HC595)

Featured Video Play Icon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
int DS_pin = 8;
int STCP_pin = 9;
int SHCP_pin = 10;

void setup()
{
 pinMode(DS_pin,OUTPUT);
 pinMode(STCP_pin,OUTPUT);
 pinMode(SHCP_pin,OUTPUT);
 
 writereg();
}

boolean registers[8];

void writereg()
{
  digitalWrite(STCP_pin, LOW);
 
  for (int i = 7; i>=0; i--)
  {
    digitalWrite(SHCP_pin, LOW);
    digitalWrite(DS_pin, registers[i] );
    digitalWrite(SHCP_pin, HIGH);
  }
 
  digitalWrite(STCP_pin, HIGH);
}

void loop()
{
 for(int i = 0; i<8; i++)
 {
  registers[i] = HIGH;
  delay(1000);
  writereg();
 }
 
 for(int i = 7; i>0; i--)
 {
  registers[i] = LOW;
  delay(1000);
  writereg();

 }
}

Leave a Reply

Your email address will not be published. Required fields are marked *