Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Listen for compass heading changes.
res
my.onCompassChange((res) => { console.log('Direction:', res.direction); });
Page({ data: { direction: 0, cardinalDirection: 'N' }, onLoad() { my.onCompassChange((res) => { this.setData({ direction: Math.round(res.direction), cardinalDirection: this.getCardinalDirection(res.direction) }); }); }, getCardinalDirection(degrees) { const directions = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW']; const index = Math.round(degrees / 45) % 8; return directions[index]; }, onUnload() { my.offCompassChange(); } });
Page({ data: { targetBearing: 45, // Target is NE arrowRotation: 0 }, onLoad() { my.onCompassChange((res) => { // Calculate rotation to point at target const rotation = this.data.targetBearing - res.direction; this.setData({ arrowRotation: rotation }); }); } });
my.startCompass