Countdown timer with seven segment display (DDD:HH:MM:SS) Arduino/72xx

A later edit: I have found a previous project that has the same time setup and the project was posted online as a event countdown timer at https://github.com/ethermania/MPCountdown(previously created to count down to the year 2012, I hope they found use for it after the apocalypse never occurred). The main sketch is in firmware / masterDigit / masterDigit.ino I have been trying to adapt it to my set up with the 7221 drivers and the 72xx LedControl library, however I have had no such luck. Luck is correct seeing as I am just trying to sort out variables and plugging in things hoping that they will work.

This model that I posted above uses a completely different way to multiplex and to display the displays due to the 74hc595's that they had used to create the project. My question is: how do I take the parts of this code that stores the total seconds, then converts it to DDD:HH:MM:SS, then takes the characters from those calculations and sends it to the display, using the 72xx LedControl library? I am taking a guess at saying that the digits would have to be grouped up in sets like:

//days setDigit(1,2, 'variable from array here', false); setDigit(1,1, 'variable from array here', false); setDigit(1,0, 'variable from array here', false); //hours setDigit(0,0, 'variable from array here', false); setDigit(0,1, 'variable from array here', false); //minutes setDigit(0,2, 'variable from array here', false); setDigit(0,3, 'variable from array here', false); //seconds setDigit(0,4, 'variable from array here', false); setDigit(0,5, 'variable from array here', false);

In a type of format that is presented in the example posted above.

I have set up all of the hardware and everything tests just fine, I am just completely lost after two weeks of trying to make this work, and if anyone had any suggestions as to how I can go about this, it would be much appreciated. If this is more of a type of post that should be in Programming, let me know, I just figured that since I have no clue as to what I am doing, it is more fit to be in Project Guidance. The original post is below for more information.

Original Post with the overall project idea: I am trying to put together some code for a countdown timer that displays the time and other things on LEDs, specifically seven segment displays and is driven by the LEDControl library (http://playground.arduino.cc/Main/LedControl)for the Arduino/7221 hardware setup.

There are: Three digits for days increment with a total time allowable of 999 days. There are two digits for hours, with a total number of hours allowable of 23 hours. Two digits for minutes, for a total of 59 minutes. Two digits for seconds, for a total of 59 seconds.

I am using two 7221's and the Arduino Micro.

The first 7221 is driving 6 digits on the HH:MM:SS display, and the second 7221 is driving the DDD (days) display and also two 10 segment bargraph displays (only eight LEDs on each bargraph are being controlled by the 7221, the other two are HIGH when power is applied to the circuit).

I have 6 input buttons and a potentiometer at hand. Not all have to be used, but I cannot have more than 6 buttons.

I have a piezo buzzer that will trigger audio.

What I need, and have no idea to do, is to have a program that will countdown the time that is inputted from a "set time" function.

When the program turns on, it goes through a predetermined "preamble" display that cycles through some custom characters, does some spinning and flashing, and then will display the time remaining on the countdown. If there is nothing going on with the counting or anything else, the display will simply show zeros. Below is the snippet for the preamble for when the display is turned on: Obviously I want to accomplish this without using the delay() function, but again, I am lost as to how the whole program is going to function, so I tested it with delay().

//GENSER SEQUENCE PREAMBLE
void genserOne() {  
  //GEnSEr
  //G  
  lc.setRow(0,0,B01011110);
  //E  
  lc.setChar(0,1,'E',false);
  //n
  lc.setRow(0,2,0x15);
  //S(5)
  lc.setChar(0,3,'5',false);
  //E
  lc.setChar(0,4,'E',false);
  //r
  lc.setRow(0,5,0x05);

  delay(400);
  //clear
  lc.clearDisplay(0);
  delay(40);

  //random 1
  lc.setRow(0,0,B01001001);

  lc.setRow(0,1,B00010101);

  lc.setRow(0,2,B00100011);

  lc.setRow(0,3,B00000011);

  lc.setRow(0,4,B01010100);

  lc.setRow(0,5,B01000011);

  delay(200);
  //clear
  lc.clearDisplay(0);
  delay(40);

  //CAluri
  //C
  lc.setRow(0,0,B01001110);
  //A
  lc.setChar (0,1,'A',false);
  //l(lowercase "L")
  lc.setRow(0,2,B00110000);
  //u
  lc.setRow(0,3,B00011100);
  //r
  lc.setRow(0,4,B00000101);
  //i
  lc.setRow(0,5,B00010000);

  delay(200);
  //clear
  lc.clearDisplay(0);
  delay(40);

  //4th Sequence
  lc.setRow(0,0,B00100011);

  lc.setRow(0,1,B00000011);

  lc.setRow(0,2,B01010100);

  lc.setRow(0,3,B01000011);

  lc.setRow(0,4,B00010011);

  lc.setRow(0,5,B00011001);

  delay(200);
  //clear
  lc.clearDisplay(0);
  delay(40);

  //Second CAluri sequence
  //C
  lc.setRow(0,0,B01001110);
  //A
  lc.setChar (0,1,'A',false);
  //l(lowercase "L")
  lc.setRow(0,2,B00110000);
  //u
  lc.setRow(0,3,B00011100);
  //r
  lc.setRow(0,4,B00000101);
  //i
  lc.setRow(0,5,B00010000);

  delay(200);
  //clear
  lc.clearDisplay(0);
  delay(40);

  //6th Sequence
  lc.setRow(0,0,B00101010);

  lc.setRow(0,1,B00000011);

  lc.setRow(0,2,B00011010);

  lc.setRow(0,3,B01001000);

  lc.setRow(0,4,B01000001);

  lc.setRow(0,5,B01001001);

  delay(200);
  //clear
  lc.clearDisplay(0);
  delay(40);

  //6th Sequence
  lc.setRow(0,0,B00010011);

  lc.setRow(0,1,B00011001);

  lc.setRow(0,2,B00100010);

  lc.setRow(0,3,B00011000);

  lc.setRow(0,4,B01000001);

  lc.setRow(0,5,B00100101);

  delay(250);
  //clear
  lc.clearDisplay(0);
  delay(75);

}

I have the two bargraphs that will run independently and also dependently to the countdown. During the countdown, the bargraph animation will speed up as the countdown time gets closer to zero (speeding up at 30 seconds, then increasing speed at 15, and then shutting off the bargraph animation at 5 seconds). The bargraph animation will happen during the countdown no matter what, however the bargraph animation can be toggled on or off when there is no time counting down. Toggled with an input button.

The bargraph animation map is below, again I don't wish there to be delays in the code, but I don't know any other way to accomplish what I need.

void bargraphRight(){
  lc.setRow(1,3,B00000000);
  delay(50);
  lc.setRow(1,3,B10000000);
  delay(50);
  lc.setRow(1,3,B11000000);
  delay(50);
  lc.setRow(1,3,B11100000);
  delay(50);
  lc.setRow(1,3,B11110000);
  delay(50);
  lc.setRow(1,3,B11111000);
  delay(50);
  lc.setRow(1,3,B11111100);
  delay(50);
  lc.setRow(1,3,B11111110);
  delay(50);
  lc.setRow(1,3,B11111111);
  delay(50);
  lc.setRow(1,3,B11111110);
  delay(50);
  lc.setRow(1,3,B11111100);
  delay(50);
  lc.setRow(1,3,B11111000);
  delay(50);
  lc.setRow(1,3,B11110000);
  delay(50);
  lc.setRow(1,3,B11100000);


...etc
}
void bargraphLeft(){
   lc.setRow(1,4,B00000000);

...etc
}

Had to "..ect" the code due to the character limit for posting.

Time is set from the input buttons; push start and the countdown starts and keeps the time left displayed on the seven segment displays. While it is counting down, there is two sets of colons between the HH:MM:SS and flash for about 100ms every 500ms and there is audio frequency from the piezo that beeps whenever the colon LEDs flash.

When the remaining time on the countdown reaches 20 seconds, the piezo audio changes, and then at 10 seconds it changes again, and at zero, it changes again and then shortly shuts off.

When the time reaches zero, it triggers some predetermined animations and then resets back to either zeros, or the time that was set before the countdown started.

The countdown can be interrupted early, and when it does, it reset and starts automatically setting the time random and automatically start counting down, then hits zero, does the after-zero operations, then sets another random time and starts counting down, etc. It will continue doing so until the device is reset and then it goes back to normal functioning, where it can be manually set.

Someone was able to accomplish pretty much what I am looking to also do, they made a video of it: http://www.youtube.com/watch?v=n5TClZxZGYY

The hardware will be run off of 5 volts, and I have all the hardware hooked up on a breadboard. I just have pretty tall goals and I am not sure on how to structure a program to accomplish what I want to do. I checked out the Time Libraries and such, but I am lost as to how about I will accomplish what I want with it, or whether or not if using the Time library will even make what I want to do easier.

I think I included everything there, but I can elaborate anything if needed. Any suggestions to break the confusion would be appreciated.