07-30-2021 09:36
07-30-2021 09:36
This may be simple, but after numerous attempts I am stumped. Is there a way to program multiple vibrations, e.g. four "bump"s in a row?
07-30-2021 10:49 - edited 07-30-2021 11:12
07-30-2021 10:49 - edited 07-30-2021 11:12
You need to import the vibration function, and you can use a for loop, like so: (Reference: https://dev.fitbit.com/build/reference/device-api/haptics/)
import { vibration } from "haptics";
Then inside a function that you are wanting to run the bumps:
for(let i=0; i<4; i++){
vibration.start("bump");
}
NOTE: I have not used this before, I wrote this on the fly. So I am unsure if you need to do a 'vibration.stop("bump")' or not after the 'start'. This should get you on the right track though!
07-30-2021 15:06
07-30-2021 15:06
Good idea, seems logical. Didn't work. Thanks anyway.
07-30-2021 15:10
07-30-2021 15:10
I wonder if you might be able to achieve this using setInterval(). Just be careful not to create an infinite loop!
07-30-2021 15:42
07-30-2021 15:42
@Gondwana you can start it this way, but can you stop a setinterval() call? If so, I'd like to know because that may be useful in the future!
07-30-2021 15:43
07-30-2021 15:43
@dzawiskie if I get the chance, I'll play around and see if I can't figure something out!
07-30-2021 15:47
07-30-2021 15:47
clearInterval(), I think. You'd need to retain a variable that represents the interval timer (returned from setInterval), and another variable to keep count.
If you were being really fancy, you'd wrap it all into a nice class or object or module. 🙂
07-30-2021 15:49
07-30-2021 15:49
Or, you could call setTimeout() for each repeat.
07-30-2021 17:07
07-30-2021 17:07
There's a small chance that something like this might work:
const vibrationRepeater = (pattern, count, interval) => {
vibration.start(pattern) // do one straight away
let counter = count - 1
let timer = setInterval(()=>{
vibration.start(pattern)
if (!--counter) clearInterval(timer)
}, interval)
}
vibrationRepeater('bump', 4, 500)
07-31-2021 04:53
07-31-2021 04:53
This would be much simpler on a Pebble.
08-02-2021 05:44