Countdown 2 digit 7 segment

Hi there, I’m attempting to finish this project for a decoration project. I have a fake rocket that needs to “fly” when the countdown arrives to 0.
I built a 2 digit countdown 7 segment display with regular white led strip. I built an amplifier stage with 1 tip122 for each segment.

I used inputs from 0 to 13 to run 14 segments in order to make a countdown from 10 to 0. I also used A5 as digital input (19).

The press of the button starts the countdown, but if not pressed it will just display a cross and a frame. Until here everything ok.

I found two problems that I don’t know how to solve.

When the countdown has started, it won’t stop until 0. Somehow, I would like it to start from 10 again even if i’m inside the countdown. But the statment if makes it finish the countdown and back to main loop before I can press that. Is ther any way to do that? I mean, that the countdown starts every time I press the button even if it’s already counting down…

The other problem is that the button doesn’t react that well. I realised the longer the wire the worst it reacts (sometimes good, sometimes not good). I connected the button throught a pulldown 10kohm resistor on A5 ( using it as digital input 19). Any ideas with that?
Thanks a lot. I attach the code.

COUNTDOWN.ino (4.17 KB)

Hi, please post your code in code tags, as explained in the forum guide in the sticky post. Also post a schematic showing how you have connected the strips and button. You don't need to show all 14 strips, just one or two.

But I can already guess what your problem is from your description. You are using the delay() function to time the countdown? If so, this will be preventing you from achieving the other things you want. Using delay() like that is beginner level coding, and I suspect it is time you took your next steps in Arduino coding. Have a look at the "Blink without delay" example sketch and the pinned forum threads about "doing more than one thing at once" etc.

First of all, I know you did not ask for this. But please use defines to your I/O. It makes the code easier to read for us.

Like:

#define button 19 (at the top of the file)
pinMode(button,INPUT);
if (digitalRead(button) == HIGH)

DELIR66:
When the countdown has started, it won't stop until 0. Somehow, I would like it to start from 10 again even if i'm inside the countdown. But the statment if makes it finish the countdown and back to main loop before I can press that. Is ther any way to do that? I mean, that the countdown starts every time I press the button even if it's already counting down....

The other problem is that the button doesn't react that well. I realised the longer the wire the worst it reacts (sometimes good, sometimes not good). I connected the button throught a pulldown 10kohm resistor on A5 ( using it as digital input 19). Any ideas with that?
Thanks a lot. I attach the code.

If I am understanding it correct, if the countdown timer is done, you want it to return to 10?

You can achieve this by copying this part of code:

  digitalWrite(8, HIGH);
  digitalWrite(9, HIGH); 
  digitalWrite(0, HIGH);  
  digitalWrite(1, HIGH); 
  digitalWrite(2, HIGH);   
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);

Above the IF statement.

If you want it to return in the middle of counting, you should not use delay's but milli's. Take a look at this code example: BlinkWithoutDelay

For the button issue, the cables could be pretty long as long as you added a pullup/pulldown resistor. You sure it isn't another problem that is causing the button to fail?

If one digit either has to display '1' or nothing, it can be driven as one bit.

Hence 8 bits are enough to drive the required display '10'..'0'

Rather than address them one bit at a time, use a lookup table for mapping the segments to be displayed, and write to them all at once with a PORT instruction. Much less cumbersome.

Suggest you use PORTC - the analog inputs , which can also be used as digital pins. Not PORTD, because bits 0 and 1 are reserved for serial comms to the host.

see
https://www.arduino.cc/en/Reference/PortManipulation

Allan