.. highlight:: java Timer ===== The `Timer `_ class schedules tasks to be executed periodically on the board. Scheduling a Task ----------------- To schedule a task, call the `scheduleTask `_ method, passing in a `Timer.Task `_ encapsulating the MetaWear commands to execute. The method returns an AsyncOperation object that wraps a controller object used to manage the scheduled task. :: import com.mbientlab.metawear.AsyncOperation; import com.mbientlab.metawear.module.Gpio; import com.mbientlab.metawear.module.Timer; final Gpio gpioModule= mwBoard.getModule(Gpio.class); // Schedule a task that reads the adc value every 1000ms (1s) AsyncOperation taskResult= mwBoard.getModule(Timer.class) .scheduleTask(new Timer.Task() { @Override public void commands() { gpioModule.readAnalogIn((byte) 0, Gpio.AnalogReadMode.ADC); } }, 1000, false); Controller ---------- The `Timer.Controller `_ class manages a scheduled task. You can `start `_, `stop `_, and `remove `_ a task. Typically, controllers are returned as a result of scheduling a task, though if you know the numerical ID of a controller, you can directly access it by calling `getController `_. :: taskResult.onComplete(new CompletionHandler() { @Override public void success(Timer.Controller result) { // start executing the task result.start() } });