Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Displaying deciseconds on timer app

ANSWERED

Hello,

 

I'm trying to build a timer app that displays a count down timer like the in-built one. However I am quite stuck in making it display the deci-seconds (10th of seconds ). Is there a way to achieve this goal?

 

Thanks!

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

I'm not sure you'll get that level of granularity, but you can try something like:

 

1. use the display api to detect when the screen comes on

2. start a timer using setInterval()

3. update the display to show the time

 

import { display } from "display";

let intervalID; display.addEventListener("change", () => { if (display.on) { start(); } else { stop(); } }) function start() { // display goes on
intervalID = setInterval(updateDisplay, 100); // 10ths second } function stop() { // display goes off
if(intervalID) { clearInterval(intervalID); } }


function updateDisplay() {
let now = new Date();
let ms = now.getMilliseconds();
// set appropriate image href
}

View best answer in original post

Best Answer
1 REPLY 1

I'm not sure you'll get that level of granularity, but you can try something like:

 

1. use the display api to detect when the screen comes on

2. start a timer using setInterval()

3. update the display to show the time

 

import { display } from "display";

let intervalID; display.addEventListener("change", () => { if (display.on) { start(); } else { stop(); } }) function start() { // display goes on
intervalID = setInterval(updateDisplay, 100); // 10ths second } function stop() { // display goes off
if(intervalID) { clearInterval(intervalID); } }


function updateDisplay() {
let now = new Date();
let ms = now.getMilliseconds();
// set appropriate image href
}
Best Answer