Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

controlling vibration intensity in android phones? is it possible?

Tags:

java

android

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.

like image 314
Mithraa Avatar asked May 22 '10 12:05

Mithraa


3 Answers

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

like image 144
Josh Avatar answered Oct 31 '22 06:10

Josh


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. 
    };
like image 30
mateusz Avatar answered Oct 31 '22 06:10

mateusz


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.

like image 27
paulscode Avatar answered Oct 31 '22 07:10

paulscode