0

I'm attempting to vary a phone's vibration according to a pattern using PWM in order to change it's speed. I'm able to get this to work:

vibrator.vibrate(patternA, 0);

but when I put the vibrator call in a loop like so:

final int[] rampIntensity = {30, 40, 50, 60, 70, 80, 90, 100};
final int[] rampTime = {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000};
for(int i=0; i <= rampIntensity.length-1; i++) {
    long endTime = System.currentTimeMillis() + rampTime[i]*60; //fetch starting time
    while((System.currentTimeMillis()) < endTime){
       vibrator.vibrate(patternFollower(rampIntensity, i), 0);
    }
}

The vibrations are sketchy at best, and eventually fail where they should increase in intensity as it goes through the pre-determined pattern. I feel as if there's something I'm missing about getting leaving this to run in a loop, but it's not coming to me.

So my question is, how can I get this method to make Vibrator class use PWM to vibrate to a pattern.

Edit: Here's the patternFollower and getVibratePattern methods. Vibrator.vibrate seems to want the pattern you feed to it as a final.

private long[] patternFollower(int[] intensity, int 
long[] pattern;
    pattern =  getVibratePattern(intensity[i]);

    return pattern;
}

private long[] getVibratePattern(int intensity) {
    long[] pattern = null;
    final long[] smooth90 = {2, 30, 2, 30}; // Smooth - 90%
    final long[] smooth80 = {3, 30, 3, 30}; // Smooth - 80%
    final long[] smooth70 = {5, 30, 5, 30}; // Smooth - 75%
    final long[] smooth60 = {5, 25, 5, 25}; // Smooth - 60%
    final long[] smooth50 = {7, 25, 7, 25}; // Smooth - 50%
    final long[] smooth40 = {3, 15, 3, 15}; // Smooth - 40%
    final long[] smooth30 = {7, 15, 7, 15}; // Smooth - 30%
    switch (intensity){
        case 90: return smooth90;
        case 80: return smooth80;
        case 70: return smooth70;
        case 60: return smooth60;
        case 50: return smooth50;
        case 40: return smooth40;
        case 30: return smooth30;
    }
    return pattern;
}
nelmstr
  • 1
  • 3

0 Answers0