Bomb Countdown

Hi Guys

Please help me.

Im stuck in a project, trying to make a countdowntimer for a prop bomb.

I have been doing a lot of trial and error with the code, so its probably quite messy, sorry☺

I´m using a 8 digits 7 segment display spreading out the minutes, seconds and tenths leaving one digit off in between each to make it look better.

The countdown starts at “4 59 00” after a 10 seconds delay. It stops at “01 02 10"

Everything looks fine, but can anybody help me make it stop at “00 02 10” instead?

Thank you☺

And the code:

#include <LedControl.h>    //We cant do anything without importing a suitable library!

// Lets start with the pinouts to the Max72xx led driver
// *****************************************************

int DIN = 7;              // Pin 1  on the Max72xx
int CLK = 6;              // Pin 13 on the Max72xx
int LOADCS = 5;           // Pin 12 on the Max72xx

int flashDelay = 100;      // delay in MS (100=1/10th second) 
int ledBrightness = 15;    // range is 0-15.  0=lowest, 15 = full power

// define the LedControl instance - if I want more I can setup lc2, lc3 etc
// ************************************************************************

LedControl lc=LedControl(DIN,CLK,LOADCS,1);    // DIN, CLK, Load/CS, 1 = only one chip MAX chip attached.

void setup()                    
{ 
  pinMode(DIN, OUTPUT);        // once only, lets make the pins outputs 
  pinMode(CLK, OUTPUT); 
  pinMode(LOADCS, OUTPUT); 

  // take pins out of power save mode.  No updates otherwise. 
  for(int index=0;index<lc.getDeviceCount();index++) { 
    lc.shutdown(index,false); 
  }

  lc.setIntensity(0,ledBrightness  ); //set the brightness 
  
  delay(10000);                  // delay
  int row = 0;                  //Set the starting position
  int chipId = 0;               //This is not strictly reqd, but if using more than one display this will be needed

  // First lets display the hours
  // ****************************

  for (int hourcountdown=001; hourcountdown>000; hourcountdown--){
    int x=hourcountdown;
    int hourones;
    int hourtens;
    hourones=x%10;
    hourtens=x/10%10;                                     // %10 divides by ten and extracts the remainder
    lc.setChar(chipId, row+8, 'h', false);                // Adds the letter H
    lc.setDigit(chipId, row+9, (byte) hourones, false);   // These two lines add the numerical hours 
    lc.setDigit(chipId, row+9, (byte) hourtens, false);   // This technique is repeated several times!

    //  Now the minutes
    for (int minutecountdown=04; minutecountdown >00; minutecountdown--){
      int y=minutecountdown;
      int minuteones;
      int minutetens;
      minuteones=y%10;
      minutetens=y/10%10;                                   // %10 divides by ten and extracts the remainder
      lc.setDigit(chipId, row+6, minuteones, true);         // These two lines add the numerical hours
      lc.setDigit(chipId, row+7, minutetens, false);        // Deja Vu?

      //  And the seconds/tenths just to make it look exciting!
      for (int seccountdown=600; seccountdown>20; seccountdown--){
        int v=seccountdown;
        int tenths;
        int secones;
        int sectens;
        int thousands;
        tenths=v%10;                                         // Again divide by 10 and calculate the remainder
        secones=v/10%10;                                      
        sectens=v/100%10;
        thousands=v/1000%10;
        lc.setDigit(chipId, row, (byte) thousands, false);
        lc.setDigit(chipId, row+1, (byte) tenths, false);      
        lc.setDigit(chipId, row+3, (byte) secones, true);    // True in the arguments activates the dot...
        lc.setDigit(chipId, row+4, (byte) sectens, false);
        delay (flashDelay);
        
}
}}}
void loop()                     // here comes the good stuff, the main loop!
{}

If I was in your place I would do the code in the loop() function and not in the setup().

but i dont want it to loop. Only play once and stop at 00 00 10

I've deleted your almost-identical post where the clock stopped at a slightly different time.

DO NOT CROSS-POST, CROSS-POSTING WASTES TIME.

for (int hourcountdown=001; hourcountdown>000; hourcountdown--){

Change the greater-than to greater-than-or-equals. Do the same in the minutes loop as well.

rasmusbaek:
but i dont want it to loop. Only play once and stop at 00 00 10

So, you want to loop until 00 00 10, but it’s OK, you can do it like that too.

Why you want to stop at that point, anyway? Why don’t stop at 00 00 00?

Anyway, I think this code will do the work:

#include <LedControl.h>    //We cant do anything without importing a suitable library!

// Lets start with the pinouts to the Max72xx led driver
// *****************************************************

int DIN = 7;              // Pin 1  on the Max72xx
int CLK = 6;              // Pin 13 on the Max72xx
int LOADCS = 5;           // Pin 12 on the Max72xx

int flashDelay = 100;      // delay in MS (100=1/10th second) 
int ledBrightness = 15;    // range is 0-15.  0=lowest, 15 = full power

// define the LedControl instance - if I want more I can setup lc2, lc3 etc
// ************************************************************************

LedControl lc=LedControl(DIN,CLK,LOADCS,1);    // DIN, CLK, Load/CS, 1 = only one chip MAX chip attached.

void setup()                    
{ 
  pinMode(DIN, OUTPUT);        // once only, lets make the pins outputs 
  pinMode(CLK, OUTPUT); 
  pinMode(LOADCS, OUTPUT); 

  // take pins out of power save mode.  No updates otherwise. 
  for(int index=0;index<lc.getDeviceCount();index++) { 
    lc.shutdown(index,false); 
  }

  lc.setIntensity(0,ledBrightness  ); //set the brightness 

    delay(10000);                  // delay
  int row = 0;                  //Set the starting position
  int chipId = 0;               //This is not strictly reqd, but if using more than one display this will be needed

  // First lets display the hours
  // ****************************

  for (int hourcountdown=1; hourcountdown >= 0; hourcountdown--){
    int x=hourcountdown;
    int hourones;
    int hourtens;
    hourones=x%10;
    hourtens=x/10%10;                                     // %10 divides by ten and extracts the remainder
    lc.setChar(chipId, row+8, 'h', false);                // Adds the letter H
    lc.setDigit(chipId, row+9, (byte) hourones, false);   // These two lines add the numerical hours 
    lc.setDigit(chipId, row+9, (byte) hourtens, false);   // This technique is repeated several times!

    //  Now the minutes
    for (int minutecountdown=4; minutecountdown >= 0; minutecountdown--){
      int y=minutecountdown;
      int minuteones;
      int minutetens;
      minuteones=y%10;
      minutetens=y/10%10;                                   // %10 divides by ten and extracts the remainder
      lc.setDigit(chipId, row+6, minuteones, true);         // These two lines add the numerical hours
      lc.setDigit(chipId, row+7, minutetens, false);        // Deja Vu?

      //  And the seconds/tenths just to make it look exciting!
      for (int seccountdown=590; seccountdown >= 0; seccountdown--){
        if (hourcountdown==0 && minutecountdown==0 && seccountdown==10) {
          while(1); // stop the program
        }
        int v=seccountdown;
        int tenths;
        int secones;
        int sectens;
        int thousands;
        tenths=v%10;                                         // Again divide by 10 and calculate the remainder
        secones=v/10%10;                                      
        sectens=v/100%10;
        thousands=v/1000%10;
        lc.setDigit(chipId, row, (byte) thousands, false);
        lc.setDigit(chipId, row+1, (byte) tenths, false);      
        lc.setDigit(chipId, row+3, (byte) secones, true);    // True in the arguments activates the dot...
        lc.setDigit(chipId, row+4, (byte) sectens, false);
        delay (flashDelay);
      }
    }
  }
}

void loop()                     // here comes the good stuff, the main loop!
{
}

I only add these lines:

       if (hourcountdown==0 && minutecountdown==0 && seccountdown==10) {
          while(1); // stop the program
        }

to force him to stop when the time to stop is reached. I change this line too:

     for (int seccountdown=590; seccountdown >= 0; seccountdown--){

because you need to count the seconds (or tenths of seconds) to be counted from 600 to 0 (and not to 20 like you had it).

BTW, in C language 5 is equal to 05, but 10 is not equal to 010, so be careful when you add zeros before your numbers.