Luke Taylor
Luke Taylor

Reputation: 9599

Android: Set power of vibration

I'm currently working on a project, where I'd like to use the vibrating motor situated inside the Android phone.

I'd figured out, that setting the right permission in the manifest and getting an instance of the vibrator:

Vibrator v = (Vibrator) game.getSystemService(Context.VIBRATOR_SERVICE);

would give me access to it. As far as I can see the only methods to make it vibrate are:

public abstract void vibrate (long milliseconds)

and

public abstract void vibrate (long[] pattern, int repeat)

Yet I'd like to have control the power of the vibration:

How can I control the power of the vibration?

Update:

Shouldn't the speed be controlled by varying voltage (or PWMing DC)?

Upvotes: 5

Views: 14015

Answers (3)

paulscode
paulscode

Reputation: 1069

True, the API does not provide a direct way to control the vibration intensity. But as you suggested in your update, 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 based on the specified strength. 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.

Upvotes: 3

K_Anas
K_Anas

Reputation: 31466

The Vibrator Class does not allow for this, you can only set the pattern as well as the duration:

vibrate(long[] pattern, int repeat)

vibrate(long milliseconds)

intensity is related to Hardware "Vibration Motor"

Upvotes: 1

Stuart
Stuart

Reputation: 126

As per the below, I don't believe it's possible to control the intensity. What you could do is use short bursts so the device doesn't vibrate as fast? But I've not tested this personally.

http://developer.android.com/reference/android/os/Vibrator.html and controlling vibration intensity in android phones? is it possible?

Upvotes: 5

Related Questions