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

Make an efficient time counter off-screen

ANSWERED

Hello,

I am trying to make a time counter in the most efficient way, but Hardware is not revealed, so I can't access the timers. I was thinking about using event of 'clock', but the clock.ontick is called just when the screen is on. I would like to make the counter work also when the screen is off, as well as for the vibration. I would like to see if it is possible to program the smartwatch as efficiently as a microcontroller.

 

Thank you and have a nice 2022!

 

Nazareno

import clock from "clock";
import * as document from "document";
import { preferences } from "user-settings";
import * as util from "../common/utils";

import { vibration } from "haptics";

// Update the clock every minute
clock.granularity = "seconds";

// Get a handle on the <text> element
const myLabel = document.getElementById("myLabel");
let counter= 0;
// Update the <text> element every tick with the current time
clock.ontick = (evt) => {
  ++counter;
  myLabel.text = `${counter}`;
  if (counter === 25){ 
    counter = 0;
    vibration.start("ring");
  }
  }

 

 

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

setInterval will work when the screen is off. Also the vibration will work.

 

Since setInterval(function,delay) the delay is not precise, but for 25 seconds it is accuracte enough. setInterval does have some impact on the battery though. 

 

When the display turns on, make sure to update the interface.

View best answer in original post

Best Answer
2 REPLIES 2

setInterval will work when the screen is off. Also the vibration will work.

 

Since setInterval(function,delay) the delay is not precise, but for 25 seconds it is accuracte enough. setInterval does have some impact on the battery though. 

 

When the display turns on, make sure to update the interface.

Best Answer

Yes, I figure it out just today! I am new to Javascript, that's the problem. Most of the microcontrollers are programmed in C.

 

Thanks.

Best Answer
0 Votes