Home AMX User Forum AMX Design Tools

Formatting a button as a timer

I have a sleep timer that I want to implement into a single button. I was wondering if it was possible, thru TPD4, to format a general-type button so that when in the off state it showed a timer with the format of 00:00. I already have this button working with a send_command ^TXT structure, where I am sending the current number of a variable that counts down every second, but it only shows as 30,29,28,27, etc. Is this possible to do with TPD4, or do I need to send a type of formatted code with my send_command ^TXT structure, where I add '00:',(nSleep)? If that is my only option, what would the best way be to program it so that I could show minutes and seconds remaining, like 19:25? I am assuming something with an arithmetic operation for the 19 and then the remainder in seconds.

Comments

  • DHawthorneDHawthorne Posts: 4,584
    It's possible to define it as a multi-state bargraph and use a send_level to it to update the display. But that method is terribly inflexible; you need to have a state defined for every increment, and if you ever change the timer range, you have to add or remove states on the panel. Far better, in my opinion, to do it in code using ^TXT. However, even done like that, you might get states skipped. NetLinx is not the best language for precise timing operations, at least not to the second, and definitely not any finer than that. Any bog down in any intermediate code, or a momentary connection hiccup to the panel, might cause it to jump a second here or there. If you have a very simple system and little going on, you might be OK, but the problem is you can't completely depend on it. I would consider, if you can't get it to decrement smoothly, increasing the interval to a five second countdown which won't fuss so much over minor delays.

    Your other option is an animated button, with the animation rate set to update the states. That, however, is also horribly inflexible, and it's very possible for the animation to get out of sync with your actual timer code. For a sleep timer, it's perhaps not enough to worry about if the button times out 2 seconds before the event fires, but that is what you have to consider.
  • Sounds like I should stick to a timeline that updates every minute, and just stick to whole minutes for the countdown.
  • vegastech wrote: »
    I have a sleep timer that I want to implement into a single button. I was wondering if it was possible, thru TPD4, to format a general-type button so that when in the off state it showed a timer with the format of 00:00. I already have this button working with a send_command ^TXT structure, where I am sending the current number of a variable that counts down every second, but it only shows as 30,29,28,27, etc. Is this possible to do with TPD4, or do I need to send a type of formatted code with my send_command ^TXT structure, where I add '00:',(nSleep)? If that is my only option, what would the best way be to program it so that I could show minutes and seconds remaining, like 19:25? I am assuming something with an arithmetic operation for the 19 and then the remainder in seconds.

    If your countdown is in seconds you can to this...
    minutes = CountinSec/60
    seconds = CountinSec mod 60
    Send_command dvTP,"'TEXT100-',itoa(minutes),':',right_string("'00',itoa(seconds)",2)"
  • kbeattyAMX wrote: »
    If your countdown is in seconds you can to this...
    minutes = CountinSec/60
    seconds = CountinSec mod 60
    Send_command dvTP,"'TEXT100-',itoa(minutes),':',right_string("'00',itoa(seconds)",2)"

    Maybe this is a dumb question, but what is the mod 60 for?
    Thanks.
  • Maybe this is a dumb question, but what is the mod 60 for?
    Thanks.

    Mod or Modulos give you the remainder of a division. So 130 mod 60 is 10.
  • kbeattyAMX wrote: »
    Mod or Modulos give you the remainder of a division. So 130 mod 60 is 10.

    Thank you.
  • Ken,

    That worked beautifully! Thank you! I had seen the modulo command in the documentation, I just didn't know how to get there mathematically. (Kinda sad for a guy that uses simple math every day.) Now I have been provided tools...I can start fishing. ;)
Sign In or Register to comment.