Formatting a button as a timer
vegastech
Posts: 369
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.
0
Comments
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.
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.
Mod or Modulos give you the remainder of a division. So 130 mod 60 is 10.
Thank you.
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.