element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Arduino Time increment question
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 3 replies
  • Subscribers 400 subscribers
  • Views 592 views
  • Users 0 members are here
  • time_t
  • time
  • arduino
Related

Arduino Time increment question

ntewinkel
ntewinkel over 13 years ago

Hi All,

 

I seem to be hitting a wall on how to do Time math on Arduino, and I'm hoping someone here might have some good ideas.

 

This is for my greenhouse sprinkler timer, to put it into context.

 

So I have an LCD display that shows the current time. That part is easy. The Time library works really well for that. I've added buttons to set the time, and all is good there.

 

Now I would like to calculate when the next time will be to run the sprinklers. And then I want to display that on the LCD under the current time.

 

For example, my display might look like:

        Time  9:42a

         Next  3:00p

 

I'm having trouble taking the current time and adding seconds or minutes to it without changing the current time. To change the current time we just need to use adjustTime(seconds). I would like to do something similar to a time_t variable.

 

I can compare two time_t structures by using the numberOfSeconds() function. To do that, time1 and time2 are converted to seconds and compared and that tells me what I need to know.

 

The problem I'm having is on how to create a time_t back from numberOfSeconds, in order to increment the time easily without having to increment seconds, check for overflow to minutes, then increment minutes and check overflow etc etc.

 

Here's what I have:

 

    long secs;

    time_t startTime;

     time_t stopTime;

 

    startTime = now();

    secs = numberOfSeconds(startTime);

    secs = secs + 90 * 60; // increment the time

     // how to convert to stopTime?

 

I'm hoping someone has a super slick solution!

 

Thanks in advance,

-Nico

  • Sign in to reply
  • Cancel

Top Replies

  • neilk
    neilk over 13 years ago +1
    Hi Nico Great project! I'll catch up with you eventually. Have you seen this? http://http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1263305457 It might be of help. All the best Neil
Parents
  • neilk
    neilk over 13 years ago

    Hi Nico

     

    Great project! I'll catch up with you eventually.

     

    Have you seen this?

     

    http://http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1263305457

     

    It might be of help.

     

    All the best

     

    Neil

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • neilk
    neilk over 13 years ago

    Hi Nico

     

    Great project! I'll catch up with you eventually.

     

    Have you seen this?

     

    http://http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1263305457

     

    It might be of help.

     

    All the best

     

    Neil

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
Children
  • ntewinkel
    ntewinkel over 13 years ago in reply to neilk

    Hi Neil,

     

    Thanks, I did briefly look at TimeAlarm before. It doesn't solve the bit about adding to the current time to find the next event time, but it does solve the other potential issue I was running into with regards to the use of time_t: it's a pain when it runs over into the next day and then the next month.

     

    To get around some of the math I reduced the number of options possible for frequency of watering, which leaves only full hours to add, but I still run into the pain of dealing with midnight rollover and then end-of-month rollover and I suppose end-of-year too. Ack details details.

     

    So I think I might use TimeAlarm because it does make it easy to set the alarm at a given time, regardless of the date.

     

    Thanks,

    -Nico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • ntewinkel
    ntewinkel over 13 years ago in reply to neilk

    ps, the wordy version of my greenhouse watering system automation is in my blog: http://www.element14.com/community/people/ntewinkel/blog/2012/07/23/greenhouse-update

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube