user148837
Member since Sep 2022 • Last active Aug 2023Most recent activity
-
-
-
- 9 comments
- 1.2k views
-
-
-
wait is a function that I added:
function wait(ms){
var start = new Date().getTime();
var end = start;
while(end < start + ms) {end = new Date().getTime();
}
}even after giving the loop inside the variable creates issue as I am running an infinite while loop. And for that, JS is first trying to finish the infinite loop ( which is not happening) keeping the calling of the handler in queue.
Does Espruino supports async/ await? This would have easily solved the issue. Or is there any way to restart the whole code after every complete run?
-
I am trying to run NRF.setRSSIHandler 10 times and print the average value. After that wait for 5 second and rerun the loop again for infinite time. But for JavaScript's callback function issue, it is not giving the expected output. I've tried using several closure solutions but none of them work. Is there any way to get the correct output?
Code:
let count = 0;
let average = 0;
//infinite loop
while (count <1){
for (let i = 0; i < 10; i++) {
NRF.setRSSIHandler( function (rssi) {
let distance = Math.pow(10, ((-56 - (rssi)) / (20))) * 3.28084;
average = average + distance;
NRF.setRSSIHandler();
});
}
console.log(average/i);
wait(5000);
}
-
How did you read the data in Bangle.js LCARS Clock end?