I want my timer will start from its previous value instead of its initial value.....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SHAIL1404
    New Member
    • May 2014
    • 4

    I want my timer will start from its previous value instead of its initial value.....

    Hey dear,
    i am making a product and in which i use a timer. I want when the product is being start the timer will run and when the product is off the timer will stop. If i again start the product the timer will start from its previous value.
    I have problem that the timer start from its initial when i start my product. Anyone please help......
  • Luk3r
    Contributor
    • Jan 2014
    • 300

    #2
    Create a global integer and make your that variable equal to your timers elapsed time while your timer is running or immediately before the break in your timer.

    Comment

    • SHAIL1404
      New Member
      • May 2014
      • 4

      #3
      will you please explain i did not get where i create global integer.

      Comment

      • SHAIL1404
        New Member
        • May 2014
        • 4

        #4
        i use this code
        Code:
        int Timer()
        {
        seconds = save_seconds;
        if(Pwr_on_mode)
        {
        if(secounds<60)
        {
        seconds++;
        }
        else if(seconds == 60)
        {
        seconds = 0;
        if(mins<60)
        {
        mins++;
        }
        else if(mins==60)
        {
        mins=0;
        hour++;
        }
        }
        }
        else if(!Pwr_on_mode)
        {
        save_seconds = seconds;
        }
        Last edited by Rabbit; May 8 '14, 03:52 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.

        Comment

        • Luk3r
          Contributor
          • Jan 2014
          • 300

          #5
          You can create global variables directly under your #include's.

          Example:
          Code:
          #include <time.h>
          
          int timerInt;
          You can then have your timer tell that integer what to be. In your scenario, you want it to be the duration of the timer.

          Example:
          Code:
          {
          	timer t;
          	t.start();
          	std::cout << "Timer started..." << std::endl;
          	while(true) {
          			if(t.elapsedTime() > timerInt) {
          			timerInt = t.elapsedTime();
          			std::cout << timerInt <<  " seconds elapsed" << std::endl;
          											}
          				}
          }

          Comment

          • donbock
            Recognized Expert Top Contributor
            • Mar 2008
            • 2427

            #6
            "I want when the product is being start the timer will run and when the product is off the timer will stop. If I again start the product the timer will start from its previous value."
            Does "when the product is off" mean that power is turned off? If so, you need some form of nonvolatile memory. This is a hardware feature.

            Does your product run on a PC? If so, you can store nonvolatile data in a file on the disk.

            Does your product run on a custom-designed embedded platform? If so, you need to ask the hardware team if any nonvolatile memory is available.

            Comment

            • SHAIL1404
              New Member
              • May 2014
              • 4

              #7
              oh yes the power is turn off. but in my product i am not using any non volatile memory. is there any way by which i can save the value of timer

              Comment

              • donbock
                Recognized Expert Top Contributor
                • Mar 2008
                • 2427

                #8
                There must be nonvolatile memory of some sort for you to retain data while power is off. Memory chip types typically used for this are EEPROM, Flash Memory, "shadow" memory (a kind of 2 ply memory where the computer only sees RAM, but that RAM is automatically backed up to EEPROM when power is cycled), and battery-backed volatile memory. Alternatively, a disk drive provides nonvolatile storage in the form of files that survive power being off.

                The definition of nonvolatile memory is memory that retains its contents while power is off. You must first arrange for the hardware of your product to provide nonvolatile memory; then you write the software to make use of that nonvolatile memory. How the software does that depends on how the hardware is implemented - we can provide no general guidelines.

                Comment

                Working...