Home › Forums › General › Programming › [solved] how in the hell to use timer
- This topic has 7 replies, 4 voices, and was last updated 11 years, 5 months ago by Hecticcc.
-
AuthorPosts
-
July 27, 2012 at 12:54 am #677
I have a very simple 2 frame strip graphic of an LED off/on. I wanted to use it as a MIDI status indicator so that when messages are being sent TO the panel, the indicator goes from off to on, then turns off after a msec or so.
I’ve got the image loaded as an uiImageButton with two values 0 for off, 1 for on. Easy enough to setModulatorValue to 1 when a MIDI message is received but I’d like the value to return to 0.. I’m thinking the timer function is the way to do this as gif89a (animated gifs) are not supported in ctrlr.. at least they don’t go past frame 1.
How would I set up a very basic timer? I’ve looked at the "DEMO Component Transforms and Animation" panel but I haven’t really been able to make much sense out of it to be honest.
I want to set the LED "button" to "ON" and a timer to run for say 20msec when midi activity is received, then have a method that turns the button back to 0 when the timer stops. . . thats’ my idea anyway.. not a big deal or even necessary for this panel, just really thought it’d be a cool touch.
Getting this down might help me also knock a few other items off my todo list
Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen
July 27, 2012 at 9:38 am #4697I think its more or less like this:
[code:2kzbf9rj]timer:setCallback (33, timerCallback) — 33 I think it’s the index of the timer
timer:startTimer(33,50) — 50 its the time in msfunction timerCallback2 (timerId)
— whatever you need here
timer:stopTimer(33)
end[/code:2kzbf9rj]July 27, 2012 at 4:10 pm #4698.
"dasfaker":7a0ssnxa wrote:I think its more or less like this:[code:7a0ssnxa]timer:setCallback (33, timerCallback) — 33 I think it’s the index of the timer
timer:startTimer(33,50) — 50 its the time in msfunction timerCallback2 (timerId)
— whatever you need here
timer:stopTimer(33)
end[/code:7a0ssnxa][/quote:7a0ssnxa]Thanks I’ll try that out. I figured the ID and ms setting from the API but I wasn’t sure how to make an action occur only after the timer stops.. No if/then statement needed then here?
Like if timer is running do this, when it stops do something else?Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen
July 27, 2012 at 4:16 pm #4699"msepsis":c1obpfaz wrote:Thanks I’ll try that out. I figured the ID and ms setting from the API but I wasn’t sure how to make an action occur only after the timer stops.. No if/then statement needed then here?
Like if timer is running do this, when it stops do something else?[/quote:c1obpfaz]You can check if the timer is running with [i:c1obpfaz]isTimerRunning (const int timerId)[/i:c1obpfaz]If you remove the line [i:c1obpfaz]timer:StopTimer(33)[/i:c1obpfaz] the timer runs forever. And the code after this line will do things once the timer is stopped.
July 27, 2012 at 7:54 pm #4700killer. works like a charm. Thanks Das!!
and just to help any others out there there was a slight typo in das’s example.. here’s the jist of what a timer should look like, it’s actually stupid simple.
[code:232eqlok]
timer:setCallback (33, timerCallback)
timer:startTimer(33,500)function timerCallback (timerId) — this function name must match the name above in the first line.
— stuff to do while timer is running
timer:stopTimer(33)
end
— stuff to do after timer has run it’s duration (here 500ms)
[/code:232eqlok]Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen
November 7, 2012 at 1:28 pm #4701I am trying to get multiple timers to work, how does one specify several unique timer id’s inside the same script (if possible)?
I have been trying by altering several things but i do not get them working.I have used the script posted by msepsis here[/url:3b6d4ur8] as starting point
for instance when i try this the timer will not start:
[code:3b6d4ur8]
timer:setCallback (1, timerCallback)
timer:startTimer(1, 500)function timerCallback (timerId) — this function name must match the name above in the first line.
— stuff to do while timer is running
timer:stopTimer(1)
end
— stuff to do after timer has run it’s duration (here 500ms)
[/code:3b6d4ur8]When i try this the timer does not stop:
[code:3b6d4ur8]
timer:setCallback (31, timerCallback)
timer:startTimer(31, 500)function timerCallback (timerId) — this function name must match the name above in the first line.
— stuff to do while timer is running
timer:stopTimer(31)
end
— stuff to do after timer has run it’s duration (here 500ms)
[/code:3b6d4ur8]And when i try another name for the timer it says "attemt to index global ‘timerOne’ (a nil value)
[code:3b6d4ur8]
timerOne:setCallback (33, timerCallback)
timerOne:startTimer(33, 500)function timerCallback (timerId) — this function name must match the name above in the first line.
— stuff to do while timer is running
timerOne:stopTimer(33)
end
— stuff to do after timer has run it’s duration (here 500ms)
[/code:3b6d4ur8]The goal is to use the timer to pause a portion of the script while waiting for an incoming sysex value, and then either continue the script or abort it, depending on the value received.
November 7, 2012 at 1:43 pm #4702Timers are a global thing, timerOne does not exist only timer exists, an example (simple one) on how to use timers:
http://ctrlrv4.svn.sourceforge.net/view … ision=1173you’ll need the nightly for this to work, you can also use a previous revision of the demo (you probably have it in your Ctrlr directory) with previous Ctrlr versions:
http://ctrlrv4.svn.sourceforge.net/view … ision=1118November 7, 2012 at 11:53 pm #4703I looked at the examples and got it working in my panel after a bit of tinkering , thank you ” title=”Smile” />
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.