CountDown Timer set up from serial monitor

Hello everyone. I want to make a countdown timer of hh:mm:ss format which i can set it up from serial monitor. I should give a value of mseconds and the timer should start counting down from this value. I found the code of the following link but i cant insert a value from serial monitor and control the timer. It works only with a preset time at the setup . Please any help ?

https://playground.arduino.cc/Main/CountDownTimer

.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

...R

Thanks. But my problem is that in my case i dont know what the variable is inside the parentheses ... Is it an integer, a string...??

unsigned long Watch, _micro, time = micros();
unsigned int Clock = 0, R_clock;
boolean Reset = false, Stop = false, Paused = false;
volatile boolean timeFlag = false;

void setup()
{
  Serial.begin(115200);
  SetTimer(0,0,10); // 10 seconds
  StartTimer();
}

I need to replace what is inside the parenthesis of Setimer(....) with a Serial input data from serial monitor

PALAVRAS:
Thanks. But my problem is that in my case i dont know what the variable is inside the parentheses ... Is it an integer, a string...??

That is clearly stated at the start of the SetTimer() function

void SetTimer(unsigned int hours, unsigned int minutes, unsigned int seconds)

...R

Need to convert a String to an integer?

int i;
void setup() {
  Serial.begin(115200);
  String str = "876";
  i = str.toInt();
}

void loop() {
  Serial.println(i);
  delay(1000);
}

Here is what i ve done so far…
As you can see is a code which combines a real time clock with a ds1307 RTC module and a coutdown Timer which is set it up from the user through the serial monitor.
It works fine in my serial monitor as you can see in the attached fotos below but it doesnt in my P10 led Module.
At my P10 DMD led module only the Time looks ok. The countdown appears as symbols,letters etc
Any help ???

#include <Wire.h>
#include "RTClib.h"
#include <SPI.h>        //SPI.h must be included as DMD is written by SPI (the IDE complains otherwise)
#include <DMD.h>       //
#include <TimerOne.h>   //
#include "SystemFont5x7.h"

#define HC12 Serial
#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);
RTC_DS1307 rtc;


void ScanDMD()
{ 
  dmd.scanDisplayBySPI();
}

unsigned long Watch, _micro, time = micros();
unsigned int Clock = 0, R_clock;
boolean Reset = false, Stop = false, Paused = false;
volatile boolean timeFlag = false;
int i;
int s;
String str = "";
char stringa[10];



void setup()
{
  
   Timer1.initialize( 3000 );           //period in microseconds to call ScanDMD. Anything longer than 5000 (5ms) and you can see flicker.
   Timer1.attachInterrupt(ScanDMD);   //attach the Timer1 inte
  
  //dmd.clearScreen(true );   //true is normal (all pixels off), false is negative (all pixels on)
  
  dmd.selectFont(SystemFont5x7);

  
  while (!Serial); // for Leonardo/Micro/Zero

  Serial.begin(9600);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
     rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // FEBRUARY 2, 2019 at 5am you would call:
     rtc.adjust(DateTime(2019, 3, 3, 2, 40, 0));
  }
   HC12.begin(9600);
    Stop = true;
   
}
  
 

void loop()
{
  
if (HC12.available() > 0) {
      
    int inbyte = HC12.read(); 
    switch (inbyte) {


  case 'a' : // SET TIMER IN SECONDS 
   memset(stringa, 0, sizeof(stringa)); // set string contents to zero
    i = HC12.readBytesUntil('\n', stringa, sizeof(stringa)-1); // Read line of input
        String sec(stringa);
        i=sec.toInt();
        SetTimer(0,0,i);
 StartTimer();
       

 break;

 case 'r' : // Reset timer 
Reset =true;
 break;
 
    } 
}
  
  CountDownTimer(); // run the timer

  // this prevents the time from being constantly shown.  
  if (TimeHasChanged() ) 
  {
  
   
    Serial.print(ShowHours());
    
    Serial.print(":");
   
     if (((Clock / 60) % 60)<10) {
      Serial.print("0");
      Serial.print(ShowMinutes());
      
     
     dmd.drawString( 0, 0, minutes , strlen(minutes()), GRAPHICS_NORMAL );
    }
    else {
    Serial.print(ShowMinutes());
    
   //dmd.drawString( 0, 0, minutes , strlen(minutes()), GRAPHICS_NORMAL );
    }
   // Serial.print(ShowMinutes());
    Serial.print(":");
    if (Clock % 60<10) {
      Serial.print("0");
      Serial.println(ShowSeconds());
      
      //dmd.drawString( 10, 0, bar , strlen(bar), GRAPHICS_NORMAL );
    }
    else {
    Serial.println(ShowSeconds());
    
    dmd.drawString( 10, 0, ShowSeconds() , strlen(3), GRAPHICS_NORMAL );
    }

  }




 DateTime now = rtc.now();

    DateTime future (now + TimeSpan(0,8,2,6)); // 
    Serial.print(future.hour(), DEC);
    Serial.print(':');
    Serial.print(future.minute(), DEC);
    Serial.print(':');
    Serial.print(future.second(), DEC);
    Serial.println();

    dmd.drawString( 13, 8, ":",1, GRAPHICS_NORMAL );
  
  char h [3];
  String str1;
  str1=String(future.hour());
  str1.toCharArray(h,3);
     dmd.drawString( 0, 8, h , strlen(h), GRAPHICS_NORMAL );
    
     
  char m [3];
  String str2;
  str2=String(future.minute());
  str2.toCharArray(m,3);
     dmd.drawString( 19, 8, m , strlen(m), GRAPHICS_NORMAL );

    
    Serial.println();
    delay(1000);

  
}



boolean CountDownTimer()
{
  static unsigned long duration = 1000000; // 1 second
  timeFlag = false;

  if (!Stop && !Paused) // if not Stopped or Paused, run timer
  {
    // check the time difference and see if 1 second has elapsed
    if ((_micro = micros()) - time > duration ) 
    {
      Clock--;
      timeFlag = true;

      if (Clock == 0) // check to see if the clock is 0
        Stop = true; // If so, stop the timer

     // check to see if micros() has rolled over, if not,
     // then increment "time" by duration
      _micro < time ? time = _micro : time += duration; 
    }
  }
  return !Stop; // return the state of the timer
}

void ResetTimer()
{
  SetTimer(R_clock);
  Stop = false;
}

void StartTimer()
{
  Watch = micros(); // get the initial microseconds at the start of the timer
  time = micros(); // hwd added so timer will reset if stopped and then started
  Stop = false;
  Paused = false;
}

void StopTimer()
{
  Stop = true;
}

void StopTimerAt(unsigned int hours, unsigned int minutes, unsigned int seconds)
{
  if (TimeCheck(hours, minutes, seconds) )
    Stop = true;
}

void PauseTimer()
{
  Paused = true;
}

void ResumeTimer() // You can resume the timer if you ever stop it.
{
  Paused = false;
}

void SetTimer(unsigned int hours, unsigned int minutes, unsigned int seconds)
{
  // This handles invalid time overflow ie 1(H), 0(M), 120(S) -> 1, 2, 0
  unsigned int _S = (seconds / 60), _M = (minutes / 60);
  if(_S) minutes += _S;
  if(_M) hours += _M;

  Clock = (hours * 3600) + (minutes * 60) + (seconds % 60);
  R_clock = Clock;
  Stop = false;
}

void SetTimer(unsigned int seconds)
{
// StartTimer(seconds / 3600, (seconds / 3600) / 60, seconds % 60);
 Clock = seconds;
 R_clock = Clock;
 Stop = false;
}

int ShowHours()
{
  return Clock / 3600;
}

int ShowMinutes()
{
  return (Clock / 60) % 60;
}

int ShowSeconds()
{
  return Clock % 60;
}

unsigned long ShowMilliSeconds()
{
  return (_micro - Watch)/ 1000.0;
}

unsigned long ShowMicroSeconds()
{
  return _micro - Watch;
}

boolean TimeHasChanged()
{
  return timeFlag;
}

// output true if timer equals requested time
boolean TimeCheck(unsigned int hours, unsigned int minutes, unsigned int seconds) 
{
  return (hours == ShowHours() && minutes == ShowMinutes() && seconds == ShowSeconds());
}


Please display your image(s) in your post so we can see it(them) without downloading it(them). See this Simple Image Upload Guide

...R