Random Vibration

Hello,
I need your help!
I have a metamotionR with an haptic motor. I would like to make it vibrate randomly throughout the day every random minutes. Dose anyone have any suggestion on how I can implement this in the easiest way? Even if it's not random, how can I make it vibrate every 30 minutes? 
Thank you very much!


Comments

  • What platform are you developing on?
  • I'm using Android!  
  • Eric, thanks for your consideration! I have read and followed that page, but I still have some problems. Could you please check my code? imageI'm not sure if I have scheduled the task right because after it won't work.


    ((Switch) view.findViewById(R.id.switch_vibration)).setOnCheckedChangeListener((buttonView, isChecked) -> {

    final Timer timerVibrate= metawear.getModule(Timer.class);
    // scheduling task
    Task<Timer.ScheduledTask> taskTask;
    taskTask = timerVibrate.scheduleAsync(10000, true, () -> metawear.getModule(Haptic.class).startMotor(50.f, (short) 1000));
    // use the created ScheduledTask object
    Timer.ScheduledTask Event;
    Event= taskTask.getResult();
    if (isChecked) {
    if ((Event = timerVibrate.lookupScheduledTask((byte) 0) != null){ //not working
    Event.start();
    }
    } else {
    Event.stop();
    Event.remove();
    }

    });
  • I'm really sorry but I don't understand why I need to use AddRouteAsync if I'm not reading or "producing data" like in the example of the temperature sensor. I just want to make the haptic motor vibrate every 30 minutes. I thought I just needed to schedule the task and then use the scheduled task object such as in my not working code.   Could you please explain better how can I deal with that? thank you..
  • edited June 2017
    Meant to point you to this line:

    Though back my original point, you have to wait for asynchronous tasks to finish before you can use their result.  Your code snippet assumes the task is finished by the time you call getResult.  You should check out Bolts Framework's README on how to use asynchronous tasks.

  • thank you Eric, last question: 
    If I schedule a Task using the Metawear timer, would it work also without bluetooth connection? If no, How can I make the board do something (Vibration) even when it is not connected to the phone?

  • Yes, the timer and commands are executed on the board and do not require a connection once programmed.
  • Eric, Do you know why scheduledtask.remove() removes the task only when I don't disconnect the board from the app? Once I disconnect the board, use it and then reconnected it to the app to cancel the task, remove() does not work anymore. How can I deal with that?
  • Are you closing the app after disconnect?  Is it successfully reconnecting before you issue the remove?
  • Yes I'm closing the app and bluetooth! after I reopen the app and the bluetooth, I reconnect it as usual. Once I press the button to stop and remove the task, it won't work.. and I don't understand why. 
  • The app loses its state when you close it.  Either keep it open in the background or serialize the MetaWearBoard object.\
  • Do you have any suggestions on scheduling Random timing tasks? with scheduleAsync I can only schedule tasks that are repeated every period. 
  • You will have to use the Android SDK to randomly schedule tasks.  The MetaWear timer does not have that capability.
This discussion has been closed.