Tonight I had some time to add the 2nd shift register. At first I wasnt sure how to pass values to each one. Turns out its as simple a processing another shift out. I also added 2 buttons. The first is a toggle that is used to arm the box. This switch will also function as a kill switch. I have gotten a missile switch cover for the switch. When the cover is closed it will throw the switch back into the off position. The 2nd button is the launch button that will trigger the count down.
Below is the updated source code.
#define Buzzer 13
#define latch 8
#define clock 12
#define data 11
#define armButton 4
#define launchButton 5
#define armedIndicator 3
#define launchIndicator 2
const byte numbers[11] = {0b11000000,0b11111001,0b10100100,0b10110000
,0b10011001,0b10010010,0b10000010,0b11111000
,0b10000000,0b10011000,0b11111111};
int count = 25;
int tens = 0;
int ones = 0;
boolean launched = false;
boolean armed = false;
int iterations = 0;
void setup(){
pinMode(latch,OUTPUT);
pinMode(data,OUTPUT);
pinMode(clock,OUTPUT);
pinMode(Buzzer,OUTPUT);
pinMode(armButton,INPUT);
pinMode(launchButton,INPUT);
pinMode(armedIndicator,OUTPUT);
pinMode(launchIndicator,OUTPUT);
Serial.begin(9600);
}
void loop(){
if(digitalRead(armButton) == HIGH){
digitalWrite(armedIndicator,LOW);
if(digitalRead(launchButton) == HIGH){
launched = true;
}
}
else{
digitalWrite(armedIndicator,HIGH);
digitalWrite(launchIndicator,HIGH);
launched = false;
tens = getTens(count);
ones = getOnes(count);
lightSegments(numbers[tens],numbers[ones]);
}
if(launched){
digitalWrite(launchIndicator,LOW);
tens = getTens(count);
ones = getOnes(count);
if(count == -1){
blinkZero();
delay(1000);
}
if(count >= 0){
lightSegments(numbers[tens], numbers[ones]);
if(count > 0){
beep(500,500);
}
else{
beep(1000,1000);
}
}
count--;
}
}
void lightSegments(byte tens, byte ones) {
Serial.print("Set Lights");
digitalWrite(latch,LOW);
shiftOut(data,clock,MSBFIRST,tens);
shiftOut(data,clock,MSBFIRST,ones);
digitalWrite(latch,HIGH);
}
void blinkZero(){
lightSegments(numbers[0], numbers[0]);
delay(1000);
lightSegments(numbers[10], numbers[10]);
}
void beep(int fDelay, int lDelay){
analogWrite(Buzzer,128);
delay(fDelay);
digitalWrite(Buzzer,LOW);
delay(lDelay);
}
int getOnes(int count){
return count % 10;
}
int getTens(int count){
return count / 10;
}







