get Time from Variable and Countdown


I'm trying to set up different Variables (Seconds) via Push Button. When I press the start Button it should Countdown.

My Problem: Variables are stored in Seconds ie 180 (for 3 minutes) but i want to get output on LCD as 03:00 How should I turn 180 into 3 and Display as 03:00, 02:59, 02:58 etc How should I display "03" and how the "00" Seconds. Another: Counting up (1, 2, 3 ...) works, but down not.

It should be solved without Delay. With the build in millis.

I searched for Days for some hints and I have got something in my Head. On the Web I found only Countdowns with Delay.

Any Ideas? Libs? Hints?

I cant believe I'm the only one with this (simple) problem.

Regards, Mav.

Use Division (/) and Modulation (%) operators.

int someValue = 180; int minutes = someValue / 60; // 3 int seconds = someValue % 60; // 0


How you format it to look like 03:00, is another process. Hint look into sprintf()

Write a function like this. I have no LCD so i used Serial for testing bur you can change all Serial.print() to LCD.print()

void printTime(int seconds){//Prints seconds passed in parameter in min:sec format
  int minutes = seconds/60;
  seconds -= 60*minutes;
  if(minutes<10) Serial.print('0');//print leading zero
  if(seconds<10) Serial.print('0');


Thank You for both of You. It's awesome how fast the community helps.

@HazardsMind This was (one of) the method's, I thought about. Unfortunatelly I was not able to get it work properly. @Nilton61 Extra Beer goes to You. I changed the Serial.print to LCD.print and it works perfectly.

I'll take a look on the countdown during the night.

Thank You again, Mav.

Im curious as to what you wrote when you tried my method.

Here is what I like to do. (Just the loop() and Im using a keypad)

void loop() 
  customKey = customKeypad.getKey();

  if (customKey)

    switch (customKey)
      case '0' ... '9':
        number = number * 10 + (customKey - '0');
      case '*':
        sprintf(buffer, "%02d:%02d", number/60, number%60);
        number = 0;
      case '#':


I’m Sorry, I don’t know. I deleted it allready.
It was not even similar to Your Code and mine doesnt work.

Now I understand what did You meant.

Thank You very much,