473,394 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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......
May 8 '14 #1
7 1251
Luk3r
300 256MB
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.
May 8 '14 #2
will you please explain i did not get where i create global integer.
May 8 '14 #3
i use this code
Expand|Select|Wrap|Line Numbers
  1. int Timer()
  2. {
  3. seconds = save_seconds;
  4. if(Pwr_on_mode)
  5. {
  6. if(secounds<60)
  7. {
  8. seconds++;
  9. }
  10. else if(seconds == 60)
  11. {
  12. seconds = 0;
  13. if(mins<60)
  14. {
  15. mins++;
  16. }
  17. else if(mins==60)
  18. {
  19. mins=0;
  20. hour++;
  21. }
  22. }
  23. }
  24. else if(!Pwr_on_mode)
  25. {
  26. save_seconds = seconds;
  27. }
May 8 '14 #4
Luk3r
300 256MB
You can create global variables directly under your #include's.

Example:
Expand|Select|Wrap|Line Numbers
  1. #include <time.h>
  2.  
  3. 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:
Expand|Select|Wrap|Line Numbers
  1. {
  2.     timer t;
  3.     t.start();
  4.     std::cout << "Timer started..." << std::endl;
  5.     while(true) {
  6.             if(t.elapsedTime() > timerInt) {
  7.             timerInt = t.elapsedTime();
  8.             std::cout << timerInt <<  " seconds elapsed" << std::endl;
  9.                                             }
  10.                 }
  11. }
May 8 '14 #5
donbock
2,426 Expert 2GB
"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.
May 8 '14 #6
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
May 10 '14 #7
donbock
2,426 Expert 2GB
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.
May 11 '14 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: TekWiz | last post by:
I've got a system that automatically generates a form. I have it set up so that the backend will return to the inital form page with an error object in sessions data (assuming the backend detected...
5
by: Leif K-Brooks | last post by:
When StringIO gets an initial value passed to its constructor, it seems to discard it after the first call to .write(). For instance: >>> from StringIO import StringIO >>> buffer =...
5
by: Coz | last post by:
Hi all, I'm looking for help again!!! I have been writing a page to update a database but now have another 'silly' problem with listbox's...Grrr... I'm trying to populate the list box with...
3
by: Nick | last post by:
I have a form that has several check boxes defaulting to checked. When the form loads, I have a cursor looping through a table that stores the name of the check boxes that need to be unchecked. ...
8
by: Lyn | last post by:
Hi, Can anyone tell me how the initial value displayed in Combo Box is determined when a form is opened? I am loading the dropdown from one field ("CategoryName") of a table, with "ORDER BY ". ...
2
by: Pete | last post by:
Is there any way to add an initial value into a databound combo box on a windows form. I have a combo box set to dropdown list so users cannot add their own items and I fill the data from a...
11
by: Philip Wagenaar | last post by:
Hello, I am using a timer object in my Windows Forms Application. Does the code in ..elapsed event run in a diffrent thread? If the interval is set to 10 milliseconds and the time to execute the...
1
by: mkrei | last post by:
I have datagrid that I format at runtime with tablestyles and adding columns. I have a DataGridBoolColumn that I have subclassed, but can't get the right result. I want to disable a cell based on...
13
by: asm23 | last post by:
Hi,I need some help to clarify the warning "initial value of reference to non-const must be an lvalue". I'm searching in this groups to find someone has the same situation like me. I found in...
1
by: jsaps33 | last post by:
Hi All, I'm wondering how I would change an initial value to a blank value if nothing gets entered into the text field. I have a form with multiple fields that visitors can enter data in to get...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.