Heres a v22 sketch for the " Bollywood Bomb " that I have scratched up from another project of mine. I havn't tested this version, I dont have time to connect up the switches and display at the moment, but it should basically work, but if you try it we can debug any problems.
You could swap the pin numbers to work on Crossroads allsinging serial board.
For some reason it won't compile without the VirtualWire library , so I left it in.
Connect four pushbuttons to negative for the run pause plus and minus setting buttons.
It drives 4 x TPIC6B595 serial register/drivers using shiftout, I have made comments about which pins go to which LED segments.
the " spare" output of the TPIC for minutes units connects to the two dots between the mins and secs, which stays on while counting down, and flashes when paused ( you could swap it round if you ant the opposite effect.)
I have put in a " bombPin " output that you could drive an LED to light for 2 seconds ( or a sounderwhatever ) when countdown reaches zero.
// Boffin1's countdown " bomb " timer with preset up down run and pause
// connect dots to spare TPIC output on minute units chip, on when counting down, flash when paused
#include <VirtualWire.h>
#define latchPin 19 // rck
#define clockPin 18 // sck
#define dataPin 16 // ser in
int tile [4];
// bitmap for which leds segements ( TPIC pins ) are lit for numbers 0 - 9, first bit for dots
// this pattern will depend on how the segments are wired up
// this pattern is for sequence = dots, e, d, c, g, b, f, a
const byte digitTable [10] = {
B01110111, B00010100, B01101101, B00111101, B00011110, B00111011, B01111011, B00010101, B01111111,B00111111 }
;
const byte blanked = B00000000;
int dotState;
int pause = HIGH;
int blank = HIGH;
int mintens = 0;
int minunits = 0;
int sectens = 0;
int secunits = 0;
int timeleft = 0;
unsigned long previousdotMillis = 0;
unsigned long previousMillis = 0;
int mintendisp;
int minunitsdisp;
int sectensdisp;
int secunitsdisp;
int plusPin = 4;
int minusPin = 5;
int runPin = 6;
int pausePin = 7;
int running;
int bombPin = 8;
//******************************************************
void setup()
{
Serial.begin(9600);
blank == HIGH;
Serial.println("setup");
pinMode ( latchPin, OUTPUT);
pinMode ( clockPin, OUTPUT);
pinMode ( dataPin, OUTPUT);
pinMode ( plusPin, INPUT);
digitalWrite(plusPin, HIGH); // set pullups
pinMode ( minusPin, INPUT);
digitalWrite(minusPin, HIGH);
pinMode ( runPin, INPUT);
digitalWrite (runPin, HIGH);
pinMode ( pausePin, INPUT);
digitalWrite(pausePin, HIGH);
digitalWrite(latchPin, LOW); // blanking all displays
for ( int k=0; k<=3; k++ ){
shiftOut(dataPin, clockPin, LSBFIRST, blank);
delay (5);
}
digitalWrite(latchPin, HIGH);
pinMode ( bombPin, INPUT);
digitalWrite(bombPin, LOW);
}
//********************************************************************
void loop ()
{
checktime();
if ( mintens + minunits + sectens + secunits >= 1 ){
timeleft = HIGH;
} // check again after countdown
else
{
timeleft = LOW ;
pause = HIGH;
} // flashing dots
unsigned long currentdotMillis = millis();
if(currentdotMillis - previousdotMillis > 500) {
previousdotMillis = currentdotMillis;
if (dotState == LOW)
{
dotState = HIGH;
}
else {
dotState = LOW;
}
showtime ();
}
if ( pause == LOW ) {
dotState = HIGH ;
}
checkbutton ();
}// end of loop
void checktime () {
if ( mintens + minunits + sectens + secunits >= 1 ) // if time still left on countdown
{
timeleft = HIGH;
}
else {
timeleft = LOW ;
pause = HIGH;
}
if (timeleft == HIGH ) {
if ( pause == LOW ) { // which means its counting down i.e. not paused in countdown
static unsigned long previousMillis;
if(millis() > previousMillis)
{
previousMillis = millis() + 1000;
secunits -- ; // countdown 1 sec
if ( secunits < 0 ){
secunits = 9;
sectens -- ;
}
if ( sectens < 0 ){
sectens = 5;
minunits -- ;
}
if ( minunits < 0 ){
minunits = 9;
mintens -- ;
}
// mintens cant get to -1 or it would have to have been 0000 and paused
Serial.print(mintens);
Serial.print(minunits);
Serial.print(" : ");
Serial.print(sectens);
Serial.println(secunits);
showtime ();
if ( mintens + minunits + sectens + secunits >= 1 ){
timeleft = HIGH;
}
else {
digitalWrite( bombPin, HIGH ) ;
timeleft = LOW ;
pause = HIGH ;
// milliseconds bombPin goes high
delay ( 2000 );
}
digitalWrite( bombPin, LOW );
}
dotState = HIGH;
} // keeps dots on while countdown
else
if ( blank == LOW ) {
flashdots ();
}
}
} // END OF CHECKTIME
void checkbutton ()
{
int plus = digitalRead( plusPin );
if ( plus == LOW ) {
secunits ++;
}
if ( secunits > 9 ){
secunits = 0 ;
sectens ++;
}
if ( sectens >5 ) {
sectens = 0;
minunits ++;
}
if ( minunits > 9 ){
minunits=0;
mintens ++;
}
if ( mintens >5 ){
mintens = 0 ;
}
int minus = digitalRead( minusPin );
if ( minus == LOW ) {
secunits --;
}
if ( secunits < 0 ){
secunits = 9;
sectens -- ;
}
if ( sectens < 0 ){
sectens = 5;
minunits -- ;
}
if ( minunits < 0 ){
minunits = 9;
mintens -- ;
}
if ( mintens < 0 ){
mintens =5 ;
}
// CHANGE THIS DELAY TO SET COUNTSPEED WHEN + or - BUTTON HELD IN
if ( plus || minus == LOW ){
delay ( 100 ) ;
showtime ();
}
// when run button pressed release pause
int runbutton = digitalRead( runPin );
if ( runbutton == LOW ) {
pause = LOW ;
}
// when pause button pressed set pause
int pausebutton = digitalRead( pausePin );
if ( pausebutton == LOW ) {
pause = HIGH ;
}
} // end of checkbutton function
void flashdots () {
unsigned long currentdotMillis = millis();
if(currentdotMillis - previousdotMillis > 500) {
previousdotMillis = currentdotMillis;
if (dotState == LOW)
{
dotState = HIGH;
}
else {
dotState = LOW;
}
showtime ();
}
if ( pause == LOW ) {
dotState = HIGH ;
}
} // end of flashdots routins
void showtime () // DISPLAY ROUTINE
{
int mintendisp = (mintens) ? digitTable [ mintens ] : 0; // zero blanking tens minutes
int minunitsdisp = digitTable [ minunits ];
int sectensdisp = digitTable [ sectens ];
int secunitsdisp = digitTable [ secunits ];
if ( dotState == HIGH ){
minunitsdisp = minunitsdisp|10000000 ;
} // adds msb to minunit to light dots when dotState high
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, mintendisp);
shiftOut(dataPin, clockPin, LSBFIRST, minunitsdisp);
shiftOut(dataPin, clockPin, LSBFIRST, sectensdisp);
shiftOut(dataPin, clockPin, LSBFIRST, secunitsdisp);
digitalWrite(latchPin, HIGH);
}