Having a problem making the timer go back to 0 after it reaches 23:59. (solved)

I’m having an issue with my timer. I have all the led’s working and everything else is fine but I want it to go back to 00:00 after it reaches 23:59. Below is my code:

#define ontime 3000

#define A 11
#define B 7
#define C 4
#define D 2
#define E 13
#define f 10
#define G 5
#define DP 3

#define CC1 12
#define CC2 9
#define CC3 8
#define CC4 6

#define numbersegments{\
{1,1,1,1,1,1,0,0},\
{0,1,1,0,0,0,0,0},\
{1,1,0,1,1,0,1,0},\
{1,1,1,1,0,0,1,0},\
{0,1,1,0,0,1,1,0},\
{1,0,1,1,0,1,1,0},\
{0,0,1,1,1,1,1,0},\
{1,1,1,0,0,0,0,0},\
{1,1,1,1,1,1,1,0},\
{1,1,1,0,0,1,1,0}\
}

byte numbers[10][8] = numbersegments;

const int segments [8] = { A, B, C, D, E, f, G, DP };

void setup(){
  pinMode(A, OUTPUT);
  pinMode(B,OUTPUT);
  pinMode(C,OUTPUT);
  pinMode(D,OUTPUT);
  pinMode(E,OUTPUT);
  pinMode(f,OUTPUT);
  pinMode(G,OUTPUT);
  pinMode(DP,OUTPUT);
  
  pinMode(CC1,OUTPUT);
  pinMode(CC2,OUTPUT);
  pinMode(CC3,OUTPUT);
  pinMode(CC4,OUTPUT);
}

void loop(){
 
 for(int digit1 = 0; digit1 < 3; digit1 ++){
   if(digit1 > 2)
   {for(int digit2 = 0; digit2 < 4; digit2 = digit2 + 1);  
   }
     else { 
            for(int digit2 = 0; digit2 < 10; digit2 = digit2 + 1){
             
 for(int digit3 = 0; digit3 < 6; digit3 ++){
 for(int digit4 = 0; digit4 < 10; digit4 ++){
 for(int t = 0; t < 5; t++){// time it takes to change number.
 
 setsegments(digit1,CC1,ontime);
 setsegments(digit2,CC2,ontime);
 setsegments(digit3,CC3,ontime);
 setsegments(digit4,CC4,ontime);
 }
 }
 }
 }
 }
 }
}

 
 void setsegments(int number, int digit, int time){
 for (int seg = 0; seg < 8; seg++){
   if (numbers[number][seg]==1) {digitalWrite(segments[seg],HIGH);}
   else {digitalWrite(segments[seg],LOW);}
 }
 digitalWrite(digit,HIGH);
 delayMicroseconds (time);
 digitalWrite(digit,LOW);

}

any solutions?

That isn't your code, because it is missing setup() and a whole lot of definitions, any of which just might be important.

In addition, you have not used Auto Format to properly parse it, and you have not posted it inside "code"tags - using the little "scroll" icon.

If you go back and modify that post with those corrections, it may be worth inspecting the code in detail.

how do i properly parse it??

lonei7:
how do i properly parse it??

On the arduino IDE select the code then pick the auto format menu option. I would not call this parsing however.

Test when you get to 24:00 or even 23:60 and reset to zero when you do.

digit2 has to go up to 9 until it gets to 23 how do i get it to change when it gets to this point. It will not let me auto format it.

Is that your code?
It is very convoluted.

What does it display when it starts to go wrong? Is it 24:00?

That is not the way to write code for that situation. You have a seriese of for loops that will have to be stopped before they end. So as I said before just reset them when they reach the limit.
Use a compound if statement to detect when the digits are at the right point.
So

If(Digit1 == 2 & Digit2 ==4){
Digit1 = 0;
Digit2 = 0;
}

lonei7:
digit2 has to go up to 9 until it gets to 23 how do i get it to change when it gets to this point. It will not let me auto format it.

Thank you for the code tags.

You are right - Auto Format is broken! I have run into this before with arrays. Here is the Auto Formatted version using some trickery:

#define ontime 3000

#define A 11
#define B 7
#define C 4
#define D 2
#define E 13
#define f 10
#define G 5
#define DP 3

#define CC1 12
#define CC2 9
#define CC3 8
#define CC4 6

#define numbersegments { \
  {1,1,1,1,1,1,0,0},\
  {0,1,1,0,0,0,0,0},\
  {1,1,0,1,1,0,1,0},\
  {1,1,1,1,0,0,1,0},\
  {0,1,1,0,0,1,1,0},\
  {1,0,1,1,0,1,1,0},\
  {0,0,1,1,1,1,1,0},\
  {1,1,1,0,0,0,0,0},\
  {1,1,1,1,1,1,1,0},\
  {1,1,1,0,0,1,1,0} }

byte numbers[10][8] = numbersegments;

const int segments [8] = { 
  A, B, C, D, E, f, G, DP };

void setup(){
  pinMode(A, OUTPUT);
  pinMode(B,OUTPUT);
  pinMode(C,OUTPUT);
  pinMode(D,OUTPUT);
  pinMode(E,OUTPUT);
  pinMode(f,OUTPUT);
  pinMode(G,OUTPUT);
  pinMode(DP,OUTPUT);

  pinMode(CC1,OUTPUT);
  pinMode(CC2,OUTPUT);
  pinMode(CC3,OUTPUT);
  pinMode(CC4,OUTPUT);
}

void loop(){

  for(int digit1 = 0; digit1 < 3; digit1 ++){
    if(digit1 > 2)
    {
      for(int digit2 = 0; digit2 < 4; digit2 = digit2 + 1);  
    }
    else { 
      for(int digit2 = 0; digit2 < 10; digit2 = digit2 + 1){

        for(int digit3 = 0; digit3 < 6; digit3 ++)
          for(int digit4 = 0; digit4 < 10; digit4 ++)
            for(int t = 0; t < 5; t++){// time it takes to change number.

              setsegments(digit1,CC1,ontime);
              setsegments(digit2,CC2,ontime);
              setsegments(digit3,CC3,ontime);
              setsegments(digit4,CC4,ontime);
            }
      }
    }
  }
}

void setsegments(int number, int digit, int time){
  for (int seg = 0; seg < 8; seg++){
    if (numbers[number][seg]==1) {
      digitalWrite(segments[seg],HIGH);
    }
    else {
      digitalWrite(segments[seg],LOW);
    }
  }
  digitalWrite(digit,HIGH);
  delayMicroseconds (time);
  digitalWrite(digit,LOW);
}

All right then, here is your solved code. Not that I would do it this way but … :astonished:

#define ontime 3

#define A 11
#define B 7
#define C 4
#define D 2
#define E 13
#define f 10
#define G 5
#define DP 3

#define CC1 12
#define CC2 9
#define CC3 8
#define CC4 6

#define numbersegments { \
 {1,1,1,1,1,1,0,0},\
 {0,1,1,0,0,0,0,0},\
 {1,1,0,1,1,0,1,0},\
 {1,1,1,1,0,0,1,0},\
 {0,1,1,0,0,1,1,0},\
 {1,0,1,1,0,1,1,0},\
 {0,0,1,1,1,1,1,0},\
 {1,1,1,0,0,0,0,0},\
 {1,1,1,1,1,1,1,0},\
 {1,1,1,0,0,1,1,0} }
 
byte numbers[10][8] = numbersegments;

const int segments [8] = { 
  A, B, C, D, E, f, G, DP };

void setup(){
  pinMode(A, OUTPUT);
  pinMode(B,OUTPUT);
  pinMode(C,OUTPUT);
  pinMode(D,OUTPUT);
  pinMode(E,OUTPUT);
  pinMode(f,OUTPUT);
  pinMode(G,OUTPUT);
  pinMode(DP,OUTPUT);

  pinMode(CC1,OUTPUT);
  pinMode(CC2,OUTPUT);
  pinMode(CC3,OUTPUT);
  pinMode(CC4,OUTPUT);
}

void loop(){

  for(int digit1 = 0; digit1 < 3; digit1 ++){
    if(digit1 == 2)
    {
      for(int digit2 = 0; digit2 < 4; digit2 ++) {
        for(int digit3 = 0; digit3 < 6; digit3 ++)
          for(int digit4 = 0; digit4 < 10; digit4 ++)
            for(int t = 0; t < 5; t++){// time it takes to change number.

              setsegments(digit1,CC1,ontime);
              setsegments(digit2,CC2,ontime);
              setsegments(digit3,CC3,ontime);
              setsegments(digit4,CC4,ontime);
            }
      }
    }
    else { 
      for(int digit2 = 0; digit2 < 10; digit2 ++) {
        for(int digit3 = 0; digit3 < 6; digit3 ++)
          for(int digit4 = 0; digit4 < 10; digit4 ++)
            for(int t = 0; t < 5; t++){// time it takes to change number.

              setsegments(digit1,CC1,ontime);
              setsegments(digit2,CC2,ontime);
              setsegments(digit3,CC3,ontime);
              setsegments(digit4,CC4,ontime);
            }
      }
    }
  }
}

void setsegments(int number, int digit, int time){
  for (int seg = 0; seg < 8; seg++){
    if (numbers[number][seg]==1) {
      digitalWrite(segments[seg],HIGH);
    }
    else {
      digitalWrite(segments[seg],LOW);
    }
  }
  digitalWrite(digit,HIGH);
  delay(time);
  digitalWrite(digit,LOW);
}

Thank you all for your help it works perfectly now. :smiley: