hires-timer
v0.1.0
Published
A high-resolution timer with callback
Downloads
3
Readme
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.