Created
November 12, 2019 13:39
-
-
Save jh3y/fdc88a6c66566516a8dbb018c338fe8c to your computer and use it in GitHub Desktop.
Frequency beep. Adjustable polling for beeping based on accelerometer magnitude.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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