Multiple timers

Home Forums General Programming Multiple timers

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #54390
    proton
    Participant
      • Topics: 19
      • Replies: 94
      • Total: 113
      • ★★

      Hi again,

      I can get this simple task working for some reason:
      I have a “trigger” method that when enabled switches 3 of my buttons ON (value 1):

      — Called when a modulator value changes
      — @mod http://ctrlr.org/api/class_ctrlr_modulator.html
      — @value new numeric value of the modulator

      trigger = function(–[[ CtrlrModulator –]] mod, –[[ number –]] value)

      ret1 = panel:getModulatorByName(“pB001”)
      ret1:setValue (1, true)
      ————————————————————
      — /// first timer here to delay the second button ///
      ————————————————————
      ret2 = panel:getModulatorByName(“pB002”)
      ret2:setValue (1, true)
      ———————————————————–
      — /// second timer here to delay the 3rd button ///
      ———————————————————–
      ret3 = panel:getModulatorByName(“pB003″)
      ret3:setValue (1, true)
      end

      It kinda works with just one timer (but sometimes I get timer error on panel loading – maybe ” if ret1 ~= nil than” would help) but with two timers it always goes south or the first timer does not stop and continues forever without letting the second timer to work.
      Any ideas or examples for multiple timers in one method ???
      Thank You!!!

      #54391
      dasfaker
      Keymaster
        • Topics: 80
        • Replies: 793
        • Total: 873
        • ★★★

        Do you stop the timers?

        #54392
        proton
        Participant
          • Topics: 19
          • Replies: 94
          • Total: 113
          • ★★

          yes, something like this:

          — Called when a modulator value changes
          — @mod http://ctrlr.org/api/class_ctrlr_modulator.html
          — @value new numeric value of the modulator
          Trigger = function(–[[ CtrlrModulator –]] mod, –[[ number –]] value)
          ret1 = panel:getModulatorByName(“pB001”)
          ret1:setValue (1, true)
          ———————————————–
          — /// timer:setCallback (0, timerCallback)
          — /// timer:startTimer(0,100)
          — /// timer:setCallback (0, timerCallback)
          ———————————————-
          ret2 = panel:getModulatorByName(“pB002”)
          ret2:setValue (1, true)

          — // timer:stopTimer(0)

          ————————————————–
          — /// timer:setCallback (1, timerCallback)
          — /// timer:startTimer(1,200)
          — /// timer:setCallback (1, timerCallback)
          ————————————————–

          ret3 = panel:getModulatorByName(“pB003”)
          ret3:setValue (1, true)

          — // timer:stopTimer(1)

          end

          #54394
          dasfaker
          Keymaster
            • Topics: 80
            • Replies: 793
            • Total: 873
            • ★★★

            This is a strange code for me. Timers are independent functions, so for each timer you have to create a function.

            This is how I do it, you call the first timer and from this first timer you call the second timer.

            — Called when a modulator value changes
            — @mod http://ctrlr.org/api/class_ctrlr_modulator.html
            — @value new numeric value of the modulator
            Trigger = function(–[[ CtrlrModulator –]] mod, –[[ number –]] value)
            ret1 = panel:getModulatorByName(“pB001″)
            ret1:setValue (1, true)
            ———————————————–
            — /// timer:setCallback (0, timerCallback0)
            — /// timer:startTimer(0,100)
            end

            function timerCallback0 (timerId)

            ret2 = panel:getModulatorByName(“pB002″)
            ret2:setValue (1, true)

            timer:setCallback (1, timerCallback1)
            timer:startTimer(1,200)

            timer:stopTimer(0)
            end

            function timerCallback1 (timerId)

            ret3 = panel:getModulatorByName(“pB003″)
            ret3:setValue (1, true)

            timer:stopTimer(1)
            end

            #54395
            proton
            Participant
              • Topics: 19
              • Replies: 94
              • Total: 113
              • ★★

              Oh, yes sure,
              I’m copy – pasting here on my iPad from the top of my head but your version looks much better i was totally missing the “function timer Callback0” and Callback1 in my script as I can recall!
              Thank You das, I’ll try it as soon as I get home!
              Cheers!

              #54396
              proton
              Participant
                • Topics: 19
                • Replies: 94
                • Total: 113
                • ★★

                Thank You das, works like a charm!
                I appreciate it very much!
                Have a great day.

              Viewing 6 posts - 1 through 6 (of 6 total)
              • The forum ‘Programming’ is closed to new topics and replies.
              There is currently 0 users and 89 guests online
              No users are currently active
              Forum Statistics
              Threads: 2,495, Posts: 17,374, Members: 77,605
              Most users ever online was 12 on January 22, 2019 3:47 pm
              Ctrlr