Just to say I'd always recommend using the event rather than polling.
While in reality there may not be a big difference in power usage, if you're polling you risk getting the same reading twice (or skipping one) if there's a minor difference in timing between the accelerometer and the interval.
Also, it looks to me like calc_ess does some things in pure JS that Espruino already provides utility functions for. E.sum and E.variance should do what's needed on the ess_values array really quickly.
There is now the health event every 10 minutes which has a 'movement' field too, and it's possible that could be used instead with basically zero extra calculation needed.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Just to say I'd always recommend using the event rather than polling.
While in reality there may not be a big difference in power usage, if you're polling you risk getting the same reading twice (or skipping one) if there's a minor difference in timing between the accelerometer and the interval.
Also, it looks to me like
calc_ess
does some things in pure JS that Espruino already provides utility functions for.E.sum
andE.variance
should do what's needed on theess_values
array really quickly.There is now the
health
event every 10 minutes which has a 'movement' field too, and it's possible that could be used instead with basically zero extra calculation needed.