I am developing a game. In which, i want do set different vibration intensities for different events. I just want know if its really possible to control the vibration intensity and duration. Any advice or reference links, could be very helpful. Thanks in advance.
I think it depends on what you mean by intensity. You can control the pattern and length of the vibration, but I don't think you can make it vibrate "stronger".
http://developer.android.com/reference/android/os/Vibrator.html
I've made a simple trick to somehow reduce the intensity of vibration. My idea is to interleave vibration intervals with silent intervals. If you have one millisecond of vibration and then one second of silence and so on it seems like it's one constant vibration but weaker than normal. You can try to increase the silence intervals to make the vibration even weaker. Here goes the code example:
int strong_vibration = 30; //vibrate with a full power for 30 secs
int interval = 1000;
int dot = 1; //one millisecond of vibration
int short_gap = 1; //one millisecond of break - could be more to weaken the vibration
long[] pattern = {
0, // Start immediately
strong_vibration,
interval,
// 15 vibrations and 15 gaps = 30millis
dot, short_gap, dot, short_gap, dot, short_gap, dot, short_gap, dot, short_gap, dot, short_gap, dot, short_gap, dot, short_gap, dot, short_gap, dot, short_gap, dot, short_gap, dot, short_gap, dot, short_gap, dot, short_gap, dot, short_gap, //yeah I know it doesn't look good, but it's just an example. you can write some code to generate such pattern.
};
PWM can be used to produce a vibration pattern of various pulse widths, resulting in lower average voltage to the vibrator motor (and thus weaker vibration output).
I've posted a simple proof of concept method here. This method will generate a pattern with the specified intensity and duration. The transition in that method isn't quite linear, so I have posted a bounty to hopefully get some alternate suggestions. Will update when I have an even better algorithm.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With