hires-timer

A high-resolution timer with callback

npm install hires-timer
2 downloads in the last week
4 downloads in the last month

hires-timer

A high-resolution timer with callback, based on this origional timer, but modified to be more accurate on low-power devices where the timer accuracy is less guarenteed.

Getting Started

Install the module with: npm install hires-timer

var HighResolutionTimer = require('hires-timer');
new HighResolutionTimer({
  duration: 1000,
  callback: function(timer) {
    var hours = Math.floor( ( ( (1000 / timer.duration) * timer.total_ticks) / 60) / 24) % 24;
    var minutes = Math.floor( ( (1000 / timer.duration) * timer.total_ticks) / 60) % 60;
    var seconds = ( (1000 / timer.duration) * timer.total_ticks) % 60;
    console.log(hours, minutes, seconds);
  }
});

Including in the browser

Include the file as a script instead

<script src="highres-timer.js"></script>
<script>
var timer = new HighResolutionTimer({
  duration: 1000,
  callback: function(timer) {
    var hours = Math.floor( ( ( (1000 / timer.duration) * timer.total_ticks) / 60) / 24) % 24;
    var minutes = Math.floor( ( (1000 / timer.duration) * timer.total_ticks) / 60) % 60;
    var seconds = ( (1000 / timer.duration) * timer.total_ticks) % 60;
    console.log(hours, minutes, seconds);
  }
});

License

Copyright (c) 2012 Tane Piper
Licensed under the MIT license.

npm loves you