I'm sorry, in my haste to clean up the code so it was more readable in the forum I missed a few things. I've checked the code below and it now compiles properly as did the original unseen code. Unfortunatly there is still no change. When calling the registerWrite function from loop it works great. When registerWrite is called from startAnimation is is not working.
/*
Halloween 2012 Coffin Prop Controller
*/
//Set up 74hc595
//Pin connected to latch pin (ST_CP) of 74HC595
const int latchPin = 8;
//Pin connected to clock pin (SH_CP) of 74HC595
const int clockPin = 12;
////Pin connected to Data in (DS) of 74HC595
const int dataPin = 11;
void setup() {
//set pins to output because they are addressed in the main loop
//This is the code for the 74hc595
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
//Reset the Chip
digitalWrite(latchPin, LOW);
digitalWrite(dataPin, LOW);
digitalWrite(clockPin, LOW);
//Setup the Serial Connection
Serial.begin(9600);
Serial.println("reset");
//Print a pretty message on the lcd that we are ready
}
void loop() {
//There is PIR code here that will actually trigger the animation.
runAnimation(); //call the function to start the animation
delay(5000);
// This works from here.
for ( int bitToSet = 0; bitToSet <=8; bitToSet++ ) {
registerWrite(bitToSet, HIGH);
Serial.println(bitToSet);
delay(1000);
}
} // End Loop
void runAnimation() {
//Start the fogger
Serial.println("fire the fogger");
registerWrite(5, HIGH); // This fails here - the serial shows that the bits are right, but nothing happens
delay(1000);
//Start strobing the light
Serial.println("Strobe the light");
registerWrite(6, HIGH);
delay(1000);
registerWrite(6, LOW);
delay(500);
registerWrite(6, HIGH);
delay(1000);
registerWrite(6, LOW);
delay(500);
registerWrite(6, HIGH);
//Pop open the coffin
Serial.println("Open the Coffin");
registerWrite(1, HIGH);
delay(1000);
registerWrite(1, LOW);
delay(500);
registerWrite(1, HIGH);
delay(1000);
registerWrite(1, LOW);
delay(500);
registerWrite(1, HIGH);
delay(1000);
//Pop up the skeleton
Serial.println("Pop the Skeleton");
registerWrite(2, HIGH);
delay(1000);
//Stop the fogger so it has time to warm up again
Serial.println("Stop the Fogger");
registerWrite(5, LOW);
delay(1000);
//Reset the prop
Serial.println("Reset the Prop");
//lower the skeleton
Serial.println("Lower the Skeleton");
registerWrite(2, LOW);
delay(1000);
//Lower the lid
Serial.println("Lower the Lid");
registerWrite(1, LOW);
delay(1000);
//Turn off the light
Serial.println("Turn of the light");
registerWrite(6, LOW);
Serial.println("Animation Finished");
}
void registerWrite(int whichPin, int whichState) {
Serial.print("called registerWrite PIN - ");
Serial.println(whichPin);
Serial.print("whichState - ");
Serial.println(whichState);
// the bits you want to send
byte bitsToSend = 0;
// turn off the output so the pins don't light up
// while you're shifting bits:
digitalWrite(latchPin, LOW);
// turn on the next highest bit in bitsToSend:
bitWrite(bitsToSend, whichPin, whichState);
Serial.print("bitsToSend - ");
Serial.println(bitsToSend);
// shift the bits out:
shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend);
// turn on the output so the LEDs can light up:
digitalWrite(latchPin, HIGH);
}