Fully autonomous AI-authored technical exercise prepared for Sonari Studio, maker of a MIDI controller. This sequence is synthetic, not a hardware test.

A phone tilt drives a binary effect switch. Near 12°, a hand resting at the edge of the gesture may report 12°, then 11°, then 13°. A stateless comparison turns those samples into on, off, on. That is a switch problem, not a circular-angle problem: these values never wrap around 0° or 360°.

Let the same angle mean “stay where you are”

Keep the current state. When off, turn on at 15° or higher. When on, turn off at 8° or lower. At 11°, both states hold. That memory is hysteresis. Save this as threshold.mjs and run node threshold.mjs; it uses no packages or sensors.

import assert from "node:assert/strict"; const angles = [0, 3, 10, 12, 11, 13, 10, 14, 12, 16, 14, 11, 9, 10, 7, 5, 0]; function update(on, degrees) { return on ? degrees > 8 : degrees >= 15; } function replay(sequence, next) { let on = false; const edges = []; sequence.forEach((degrees, index) => { const after = next(on, degrees); if (after !== on) edges.push([index, degrees, after]); on = after; }); return edges; } assert.deepEqual(replay(angles, (_, deg) => deg >= 12), [ [3, 12, true], [4, 11, false], [5, 13, true], [6, 10, false], [7, 14, true], [11, 11, false], ]); assert.deepEqual(replay(angles, update), [[9, 16, true], [14, 7, false]]); assert.deepEqual(replay([0, 14, 14, 0], update), []); assert.equal(update(false, 15), true); assert.equal(update(true, 8), false); assert.equal(update(false, 11), false); assert.equal(update(true, 11), true); console.log("Replay: six vs two edges. Boundary, memory, and under-travel checks pass."); 

Read the two failure cases together

The single threshold flips at indices 3, 4, 5, 6, 7, and 11. Separate thresholds flip at 9 and 14. In both cases the first sample starts off and is not counted as a transition. A hand that only reaches 14° won’t engage the second switch at all. A wider gap can stop unwanted edges while making a deliberate move harder to trigger.

Use a resting angle taken in the actual playing grip. Compare ordinary resting movement with the smallest gesture the player can comfortably repeat. Pick an engage point between them and a release point that feels right on the return. Log the two edges, not just the angle. For a real connection, define what happens on disconnect or stale input so the effect does not remain on by accident.

If you need a true toggle that stays on between tilts, detect the rising edge, re-arm on release, and toggle the downstream state only on each new engage. The example here implements a held switch, not a latching toggle.

A published wearable-music prototype used sensor orientation to trigger chord choices. This exercise is about one simpler two-state effect and is not a reproduction of that study.