besides the flashing lights, everything works as planned.
After some trial and error.

<i>
</i>//**************************************************************//
// Name : Ghost Trap Electronics with ARDUINO nano //
// Author : FrankNBuster //
// Date : 03 Sep, 2015 //
// Version : 1.0 //
// Notes : Code for using two 74HC595 Shift Registers //
// : to make a 12 piece bargraph and an extra LED //
// : operates 2 servos for doors, //
// : a motor for vibrations //
// : a buzzer and and extra red LED //
//****************************************************************
#include <Servo.h>
Servo rightservo; // create servo object to control right door servo
Servo leftservo; // create servo object to control left door servo
int latchPin = 8; //Pin connected to ST_CP of 74HC595
int clockPin = 12; //Pin connected to SH_CP of 74HC595
int dataPin = 11; //Pin connected to DS of 74HC595
int beeperPin = 7; //Pin Connected to Beeper
int red_led = 2; //Pin connected to red LED
int motor = 4; //Pin connected to motor
int left_val, right_val; // Servo control bytes
//holders for information you're going to pass to shifting function
byte dataLOW;
byte dataHIG;
byte dataArrayLOW[15];
byte dataArrayHIG[15];
void setup() {
//set pins to output because they are addressed in the main loop
pinMode(beeperPin, OUTPUT);
pinMode(red_led, OUTPUT);
pinMode(motor, OUTPUT);
leftservo.attach(5); // attaches the servo on pin 5 to the servo object
rightservo.attach(6); // attaches the servo on pin 6 to the servo object
pinMode(latchPin, OUTPUT);
Serial.begin(9600);
//lower half
dataArrayLOW[0] = 0x00;
dataArrayLOW[1] = 0x01;
dataArrayLOW[2] = 0x03;
dataArrayLOW[3] = 0x07;
dataArrayLOW[4] = 0x0F;
dataArrayLOW[5] = 0x1F;
dataArrayLOW[6] = 0x3F;
dataArrayLOW[7] = 0x7F;
dataArrayLOW[8] = 0xFF;
dataArrayLOW[9] = 0xFF;
dataArrayLOW[10] = 0xFF;
dataArrayLOW[11] = 0xFF;
dataArrayLOW[12] = 0xFF;
dataArrayLOW[13] = 0xFF;
dataArrayLOW[14] = 0xFF;
//upper half
dataArrayHIG[0] = 0x00;
dataArrayHIG[1] = 0x00;
dataArrayHIG[2] = 0x00;
dataArrayHIG[3] = 0x00;
dataArrayHIG[4] = 0x00;
dataArrayHIG[5] = 0x00;
dataArrayHIG[6] = 0x00;
dataArrayHIG[7] = 0x00;
dataArrayHIG[8] = 0x00;
dataArrayHIG[9] = 0x01;
dataArrayHIG[10] = 0x03;
dataArrayHIG[11] = 0x07;
dataArrayHIG[12] = 0x0F;
dataArrayHIG[13] = 0x1F;
dataArrayHIG[14] = 0x3F;
}
void loop() {
int count;
//clear bargraph and status LED
clear_bargraph();
//set servos to default (close), value has to be determined when servo is built in
rightservo.write(0);
leftservo.write(0);
// wait 5 seconds
delay(1000);
// beep 2 times
beep(75);
delay(150);
beep(60);
// wait 5 seconds
delay(1000);
// open doors
rightservo.write(180); // value has to be determined when servo is built in
leftservo.write(180); // value has to be determined when servo is built in
// flash lights (3 green, 2x3 white, 3 blue) randomly for 10 seconds
//
// to be done
//
delay(1000);
// close door
rightservo.write(0); // value has to be determined when servo is built in
leftservo.write(0); // value has to be determined when servo is built in
// wait 3 seconds
delay(1000);
//fill bargraph and status light
for (int j = 0; j < 14; j++) {
//load the light sequence you want from array
dataLOW = dataArrayLOW[j];
dataHIG = dataArrayHIG[j];
//ground latchPin and hold low for as long as you are transmitting
digitalWrite(latchPin, 0);
//move 'em out
shiftOut(dataPin, clockPin, dataHIG);
shiftOut(dataPin, clockPin, dataLOW);
//return the latch pin high to signal chip that it
//no longer needs to listen for information
digitalWrite(latchPin, 1);
delay(75);
}
delay(425); //wait a tad bit longer before the yellow status LED lights up
dataLOW = dataArrayLOW[14];
dataHIG = dataArrayHIG[14];
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, dataHIG);
shiftOut(dataPin, clockPin, dataLOW);
digitalWrite(latchPin, 1);
// wait 2 seconds, then
delay(2000);
// "ghost in trap": 30 times blink red LED and beep, randomly operate motor
for (count=0; count<30; count++) {
digitalWrite(red_led,1);
beep(300);
delay(700);
digitalWrite(red_led,0);
delay(1000);
// randomly start the motor for a short moment to simulate the ghost banging around in the trap
if (random(10)>4)
{digitalWrite(motor, 1);
delay(random(0)*100);
digitalWrite(motor,0);
}
}
clear_bargraph();
while(1==1) {
// stop here
}
}
// the heart of the program
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
// This shifts 8 bits out MSB first, on the rising edge of the clock, clock idles low
//internal function setup
int i=0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);
//clear everything out just in case to, prepare shift register for bit shifting
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
for (i=7; i>=0; i--) {
digitalWrite(myClockPin, 0);
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}
//Sets the pin to HIGH or LOW depending on pinState
digitalWrite(myDataPin, pinState);
//register shifts bits on upstroke of clock pin
digitalWrite(myClockPin, 1);
//zero the data pin after shift to prevent bleed through
digitalWrite(myDataPin, 0);
}
//stop shifting
digitalWrite(myClockPin, 0);
}
void beep(int time) {
// beep 2 times
digitalWrite(beeperPin, 1);
delay(time);
digitalWrite(beeperPin, 0);
}
void clear_bargraph() {
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, 0);
shiftOut(dataPin, clockPin, 0);
digitalWrite(latchPin, 1);
}