Led

The Led module interacts with the on-board LED. We have a blog post that takes a more in depth look at the module. While it is for the older APIs, the attributes are still pertinent for the updated Led class.

Setting Patterns

LED patterns function as a pulse with four main parameters to modify: rise time, high time, fall time, and duration. These parameters are modified using the ColorChannelEditor and each color channel (rgb) is configured independent of the other colors, allowing you to program different patterns for each color.

import com.mbientlab.metawear.module.Led;

// Set the blue channel to turn on for 5 seconds
mwBoard.getModule(Led.class).configureColorChannel(Led.ColorChannel.BLUE)
    .setRiseTime((short) 0).setPulseDuration((short) 1000)
    .setRepeatCount((byte) 5).setHighTime((short) 500)
    .setHighIntensity((byte) 16).setLowIntensity((byte) 16)
    .commit();

Pattern Playback

Controlling the pattern playback is handled with the play, pause, and stop methods. The stop method also functions to clear the programmed patterns and the play method has an autoplay feature that will play any pattern as soon as it is programmed.

import com.mbientlab.metawear.module.Led;

Led ledModule= mwBoard.getModule(Led.class);

// Immediately play a pattern when it is programmed,
// play any patterns already programmed
ledModule.play(true);

// Stop playing patterns and clear all programmed patterns
ledModule.stop(true);