Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Multiple vibrations

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?

Best Answer
0 Votes
10 REPLIES 10

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!

 

Best Answer
0 Votes

Good idea, seems logical.  Didn't work.  Thanks anyway.

Best Answer
0 Votes

I wonder if you might be able to achieve this using setInterval(). Just be careful not to create an infinite loop!

Peter McLennan
Gondwana Software
Best Answer
0 Votes

@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!

Best Answer
0 Votes

@dzawiskie if I get the chance, I'll play around and see if I can't figure something out!

Best Answer
0 Votes

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. 🙂

Peter McLennan
Gondwana Software
Best Answer

Or, you could call setTimeout() for each repeat.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

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)
Peter McLennan
Gondwana Software
Best Answer

This would be much simpler on a Pebble.

Best Answer
0 Votes

@Gondwana  Seems like a good idea but may be there needs to be a vibration.stop() somewhere in case the previous one hasn't finished in which case it may be ignored, so the desired result might not be correct, especially if the interval is short.

Author | ch, passion for improvement.

Best Answer