01-11-2022 17:14
01-11-2022 17:14
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");
}
}
Answered! Go to the Best Answer.
01-12-2022 04:14
01-12-2022 04:14
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.
01-12-2022 04:14
01-12-2022 04:14
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.
01-12-2022 09:01
01-12-2022 09:01
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.