adccommunitymod (AutomationDirect) asked a question.

Productivity Simple Timer to Display Minutes and Seconds

Created Date: January 30,2014

Created By: amstipe

**** This post has been imported from our legacy forum. Information in this post may be outdated and links contained in the post may no longer work.****

Hi everyone, I'm working on an application where the operator is going to use a C-more to enter a time, generally from 10 seconds up to 25 minutes. That will be used as a preset for a timer. I would then like to display the current time in standard digital clock format mm:ss. I will use separate numeric entries on the C-more for the minutes and seconds and then will use a math block to convert it to ms. That part is easy. I 've come up with the following. Can anyone think of a less complicated way to do this where I don't need an extra timer and a counter which add to the complexity of the system? (I have 35 blocks of code in total that I need to do this with along with lots of other code for each block. So simplicity is key to saving me time) https://lh3.googleusercontent.com/-PEhdSaQYZb0/Uurk2KsPbZI/AAAAAAAAAmI/Sn2-AzI6CMw/w863-h511-no/timerMinandSecdisplay.bmp


  • adccommunitymod (AutomationDirect)

    Created Date: January 31,2014

    Created by: Tinker

    given timerCurrent as an integer number of 10ms intervals:

    Minutes2Display = int(timerCurrent / 6000)

    as written this assuems that you have an int() function and that it truncates rather than rounds the fractional portion, if it rounds, there may be something like a floor() function that could be used instead. But actualy, since you are doing integer math, the resuslts will likely be truncated anyway rather than being promoted to a float, I added the int() just to be clear that we are only interested in the integer portion. (they have these "typeless " languages these days that can do all sorts of bizzare things so I like to try to be clear)

    Seconds2Display = int((TimerCurrent MOD 6000) / 100)

    again the int() is probably redundant

    if you want to count down from the set time, replace timerCurrent above with (TimerPreset - timerCurrent)

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: January 31,2014

    Created by: bcarlton

    Check to see if the division truncates or rounds. I couldn't find information in the P3000 documentation. Though a small test program should quickly establish which one happens. E.g. what is the integer result of 31/60?

  • adccommunitymod (AutomationDirect)

    Created Date: January 31,2014

    Created by: dnj

    P3000 rounds. Using Integer, 31/60 gives you result of 1.

  • adccommunitymod (AutomationDirect)

    Created Date: January 30,2014

    Created by: amstipe

    Hi everyone,

    I'm working on an application where the operator is going to use a C-more to enter a time, generally from 10 seconds up to 25 minutes. That will be used as a preset for a timer. I would then like to display the current time in standard digital clock format mm:ss. I will use separate numeric entries on the C-more for the minutes and seconds and then will use a math block to convert it to ms. That part is easy.

    I 've come up with the following. Can anyone think of a less complicated way to do this where I don't need an extra timer and a counter which add to the complexity of the system? (I have 35 blocks of code in total that I need to do this with along with lots of other code for each block. So simplicity is key to saving me time)

    https://lh3.googleusercontent.com/-PEhdSaQYZb0/Uurk2KsPbZI/AAAAAAAAAmI/Sn2-AzI6CMw/w863-h511-no/timerMinandSecdisplay.bmp

    Expand Post