Bangle.setLCDMode('120x120');
g.clear();
g.setFont("6x8");
const Width = g.getWidth();
const Height = g.getHeight();
/**** show screen ****/
g.drawString('Accelerometer', 5,5);
g.drawString('x:', 10,25);
g.drawString('y:', 10,40);
g.drawString('z:', 10,55);
g.drawString('diff:', 10,70);
g.drawString('mag:', 10,85);
g.drawString('Tap to start', 5,105);
/**** Accelerometer Monitoring ****/
function showAccelerometerValues (ValueSet) {
g.clearRect(45,25, Width,105);
g.drawString('' + ValueSet.x, 45,25);
g.drawString('' + ValueSet.y, 45,40);
g.drawString('' + ValueSet.z, 45,55);
g.drawString('' + ValueSet.diff, 45,70);
g.drawString('' + ValueSet.mag, 45,85);
g.flip();
}
/**** install touch event handler ****/
let monitoringAccelerometer = false;
function toggleAccelerometer () {
g.clearRect(45,105, Width,Height);
if (monitoringAccelerometer) {
Bangle.removeAllListeners('accel');
g.drawString('Tap to start', 5,105);
} else {
Bangle.on('accel',showAccelerometerValues);
g.drawString('Tap to stop', 5,105);
}
g.flip();
monitoringAccelerometer = ! monitoringAccelerometer;
}
setWatch(toggleAccelerometer, BTN4, {edge:"rising", debounce:50, repeat:true});
setWatch(toggleAccelerometer, BTN5, {edge:"rising", debounce:50, repeat:true});
g.flip();