I'm currently working on a project where a phone receives an int by bluetooth from a distance sensor. I want the phone to vibrate differently depending on how far an object is from the sensor. If the object is very close, the phone should vibrate strongly, but if it is far away, the phone should vibrate weakly.
From what I understand, there doesn't seem to be any way of controlling the intensity of vibration directly in Java. I intend to deploy this program on many phones, not just Nokia devices, so I need a method that works on all Java ME devices.
Currently I have the following code:
It's very messy, but the idea is that the lower intensity (1), will vibrate for a shorter period than the highest (5), and will also stop for longer. The result is that the lower intensities give small bursts of vibration, while the highest vibrates consistently.Code:public void vibrate(int v) { // v will be an int between 1 and 5 for (int i=0; i<1000; i+=(int)250/v) { Display.getDisplay(midlet).vibrate(10*v); // vibrate for 10 times v - 10 to 50ms try { Thread.sleep((int) 250/v); // sleep for longer when the desired intensity is lower } catch (Exception e) {} } }
It works, but I can't imagine it's terribly good for the vibration motor. Does anyone else have experience with a similar situation or have any suggestions? Thanks.

Reply With Quote
I've never seen a phone damaged by excessive or inappropriate use of the vibration mechanism, but I'm not a mechanical engineer, I can't really comment on what such a mechanism is likely to withstand. You might want to play some of the phone's ring-tones with vibrate enabled, see how rapidly they switch vibrate on and off.

