Skip to content

Instantly share code, notes, and snippets.

@jh3y
Created November 12, 2019 13:39
Show Gist options
  • Save jh3y/fdc88a6c66566516a8dbb018c338fe8c to your computer and use it in GitHub Desktop.
Save jh3y/fdc88a6c66566516a8dbb018c338fe8c to your computer and use it in GitHub Desktop.
Frequency beep. Adjustable polling for beeping based on accelerometer magnitude.
//Bangle.beep(10000, 10000)
let b = null;
let freq = 5000;
let radius = 0;
let DURATION = 50;
const LOWER = 500;
const LOWER_MAG = 0.97;
const UPPER_MAG = 1.03;
const UPPER = 10000;
const interpolate = (input, low, high) => ((input - LOWER_MAG) / (UPPER_MAG - LOWER_MAG)) * (high - low) + low;
setWatch(() => (DURATION = Math.min(DURATION + 50, 1000)), BTN1, { repeat: true});
setWatch(() => (DURATION = Math.max(0, DURATION - 50)), BTN3, { repeat: true});
Bangle.on('accel', (props) => {
//g.clear();
//E.showMessage(JSON.stringify(x.mag));
// value between 0.97 and 1.02
// value was between 1 and 5
console.log(JSON.stringify(props));
freq = interpolate(props.mag, LOWER, UPPER);
radius = interpolate(props.mag, 5, 50);
console.log(freq);
});
// Then continuously trigger small beeps that reference the frequency on each round
const beep = () => {
g.clear();
//E.showMessage(DURATION);
g.drawCircle(120, 120, radius);
Bangle.beep(DURATION, freq).then(beep);
};
beep();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment