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 ?…