I'm trying to use a shift register to shifout. Heres a piece of code that i worte base on my understanding of the shift out tutorial. I'm trying to set all the outputs to low except for the first 3 bits whose state i keep toggling at the end of the loop. I've connected 3 leds to these outputs to check if it works and unfortunately it doesn't seem to work. So whats wrong with my code?
my understanding is as follows
Step 1: Set Latch to Low
Step 2: Pulse the Clock Pin to High and pass 1 bit of data to the data pin - repeat step 2 eight times
step 3: pulse clock pin to low
Step 4: Set Latch pin to high
Am i right?
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;
int a = 0, b = 1, c = 0;
int i = 0;
void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop()
{
digitalWrite(latchPin,0);
for(i=0; i<5; i++)
{
digitalWrite(clockPin, 1);
digitalWrite(dataPin, 0);
}
digitalWrite(clockPin, 1);
digitalWrite(dataPin, c);
digitalWrite(clockPin, 1);
digitalWrite(dataPin, b);
digitalWrite(clockPin, 1);
digitalWrite(dataPin, a);
digitalWrite(clockPin, 0);
delay(1000);
if(a ==0 && b ==1 && c==0)
{
a = 1;
b = 0;
c = 1;
}
else
{
a = 0;
b = 1;
c = 0;
}
}