Hello all, this is the first time I have ever posted a question on a forum so forgive me if I am out of order in anyway.
I am trying to setup a various set of LED pattern, using a 595 Shift Register. I got the original code off of an instructables tutorial ( http://www.instructables.com/id/8-LED-Chaser-with-74HC595-8-Bit-Shift-Register/?ALLSTEPS ).
The Original Code is a "Larson Scanner" type pattern. I wanted to break the patterns down and place them in their own individual functions. Once I did that however, the Arduino seems to hang up.
The Wiring for the Instructables code works fine, so I know its a coding issue.
Any help would be appreciated. Thank you. my coding is below
//595 LED Patterns
//G Cheng 1/5/13
//Filename Various595Patterns
//Code for Using a 74HC595 Shift Register
//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;
////Pin connected to single LED for display purposes
int led = 4;
/////595 Patterns
byte LarsonScannerPattern[30] = {
B00000001, 100,
B00000010, 100,
B00000100, 100,
B00001000, 100,
B00010000, 100,
B00100000, 100,
B01000000, 100,
B10000000, 100,
B01000000, 100,
B00100000, 100,
B00010000, 100,
B00001000, 100,
B00000100, 100,
B00000010, 100
};
byte AscendingPattern[16] = {
B00000001, 100,
B00000010, 100,
B00000100, 100,
B00001000, 100,
B00010000, 100,
B00100000, 100,
B01000000, 100,
B10000000, 100
};
byte DescendingPattern[16] = {
B10000000, 100,
B01000000, 100,
B00100000, 100,
B00010000, 100,
B00001000, 100,
B00000100, 100,
B00000010, 100,
B00000001, 100
};
void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(led, OUTPUT);
}
void loop()
{
digitalWrite(led, HIGH); //light when loop starts
LarsonScanner();
//displayLED();
//ascending();
//displayLED();
//descending();
//displayLED();
digitalWrite(led, LOW); //dim at end of loop
delay(100);
}
void displayLED()
{
for(int count = 0; count < 4; count++)
{
digitalWrite(led, HIGH);
delay(200);
digitalWrite(led,LOW);
delay(200);
}
}
void LarsonScanner()
{
int index = 0;
int count = sizeof(LarsonScannerPattern) / 2;
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, LarsonScannerPattern[index*2]);
digitalWrite(latchPin, HIGH);
delay(LarsonScannerPattern[(index * 2) + 1]);
//delay(50);
index++;
if (index >= count){
index = 0;
}
}
void ascending()
{
int index = 0;
int count = sizeof(AscendingPattern) / 2;
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, AscendingPattern[index*2]);
digitalWrite(latchPin, HIGH);
//delay(patterns[(index * 2) + 1]);
delay(25);
index++;
if (index >= count){
index = 0;
}
}
void descending()
{
int index = 0;
int count = sizeof(DescendingPattern) / 2;
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, DescendingPattern[index*2]);
digitalWrite(latchPin, HIGH);
//delay(patterns[(index * 2) + 1]);
delay(25);
index++;
if (index >= count){
index = 0;
}
}