title: dynamically change ticker interval
body: <p>I would like to change my ticker interval dynamically. </p>
  
  <p>I've written down an example to show you how I did. My use case is something else than an "accelerometer" but I hope that it gives you an idea. </p>
  
  <p><a href="http://play.golang.org/p/6ANFnoE6pA" rel="noreferrer">http://play.golang.org/p/6ANFnoE6pA</a></p>
  
  <pre><code>package main
  
  import (
      "time"
      "log"
      "fmt"
  )
  
  func main() {
      interval := float64(1000)
  
      ticker := time.NewTicker(time.Duration(interval) * time.Millisecond)
      go func(){
          counter := 1.0
          for range ticker.C {
              log.Println("ticker accelerating to " + fmt.Sprint(interval/counter) + " ms")
              ticker = time.NewTicker(time.Duration(interval/counter) * time.Millisecond)
              counter++
          }
          log.Println("stopped")
      }()
      time.Sleep(5 * time.Second)
      log.Println("stopping ticker")
      ticker.Stop()
  }
  </code></pre>
  
  <p>What is wrong is that the ticker will always "tick" every seconds and it doesn't accelerate... Any idea?</p>