B4A Class MultiTimer Snippet

Discussion in 'Additional libraries, classes and official updates' started by derez, Jul 5, 2014.

  1. derez

    derez Expert Licensed User

    If you need a timer that ticks by two or three different intervals, one after the other, here it is, with DblTimer and TriTimer classes.
    Edit: This solution is so dumb I wonder why nobody had anything to say about it, guess I'm too respected here...
    Edit: I see now that this trick is in Erel's post here https://www.b4x.com/android/forum/threads/iot-traffic-light-with-raspberry-pi.57889/...
    The following snippet does it for any combination of intervals and number of intervals:
    Code:
    Sub Process_Globals
    ....
        
    Private start As Long
        
    Private lst As List
        
    Private count As Int = 0
        
    Private timer1  As Timer
    End Sub

    Sub AppStart ' or Activity_Create
       lst.Initialize
       lst.Add(
    1000)
       lst.Add(
    2000)
       lst.Add(
    5000)
       timer1.Initialize(
    "timer1",1000)
       timer1.Enabled = 
    True
       start = 
    DateTime.Now
    end sub

    Sub timer1_Tick
       
    Dim hit As Int = (DateTime.Now - start)/DateTime.TicksPerSecond
       
    Log( hit)
       count = (count + 
    1mod lst.size
       timer1.Interval = lst.Get(count)
    End Sub
     
    Last edited: Jan 29, 2016
    ahorro1, tuhatinhvn, biggiu and 2 others like this.
  2. nidpea04

    nidpea04 Member Licensed User

    thank you.
     
  3. derez

    derez Expert Licensed User

    Changed to a snippet with much simpler solution !, see first post.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice