Changing the LED Colors

Hello,
I'm trying to write an Android App that chnages the LED color depending on Data I get with a frequency of 60 Hz.
I'm using a Metawear CPro. The Data consists of one double value changing in a Range between 0 and 5. When connecting the CPro the LED should illuminate blue and stop after a while (works pretty well). If the Data value is under 2, the LED should turn green and if greater than 2 it should turn red. Still i get some problems with switching from green to red and viceversa. The LED lags behind a lot (around some seconds) and blinks even though it shouldn't. In addition it doesn't clear the LED patterns, meaning that the light sometimes is yellow, or even orange.

Is there anything I can do to get my LED playing just fine?

Here my code
(the ledToggle is a boolean switching between true and false depending on the data value)
if(ledToggle)
{
led.stop(true);
led = board.getModule(Led.class);
led.editPattern(Led.Color.GREEN)
.riseTime((short) 0)
.pulseDuration((short) 10)
.repeatCount((byte) 5)
.highTime((short) 5)
.highIntensity((byte) 16)
.lowIntensity((byte) 16)
.commit();
led.play();
}
else if(!ledToggle)
{
led.stop(true);
led = board.getModule(Led.class);
led.editPattern(Led.Color.RED)
.riseTime((short) 0)
.pulseDuration((short) 10)
.repeatCount((byte) 5)
.highTime((short) 5)
.highIntensity((byte) 16)
.lowIntensity((byte) 16)
.commit();
led.play();
}

Comments

  • Post the full metawear code you are using.
  • In the oncreate function

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //**** some code *****
    handler.post(tickUi);

    private final Runnable tickUi = new Runnable() {
    @Override
    public void run() {
    //*** some code ***
    // the value ledStale becomes true as soon as the board is connected
    // to avoid the null pointer reference
    if (ledStale)
    {
    updateLed();
    }

    handler.postDelayed(tickUi, 1000 / 60);
    }
    };

    private void updateLed()
    {
    // the value led toggle changes with a frequency of 60 Hz depending on an other
    // value in the code

    if(ledToggle)
    {
    led.stop(true);
    led = board.getModule(Led.class);
    led.editPattern(Led.Color.GREEN)
    .riseTime((short) 0)
    .pulseDuration((short) 10)
    .repeatCount((byte) 5)
    .highTime((short) 5)
    .highIntensity((byte) 16)
    .lowIntensity((byte) 16)
    .commit();
    led.play();
    }
    else if(!ledToggle)
    {
    led.stop(true);
    led = board.getModule(Led.class);
    led.editPattern(Led.Color.RED)
    .riseTime((short) 0)
    .pulseDuration((short) 10)
    .repeatCount((byte) 5)
    .highTime((short) 5)
    .highIntensity((byte) 16)
    .lowIntensity((byte) 16)
    .commit();
    led.play();
    }
    }

    @Override
    public void onServiceConnected(ComponentName componentName, IBinder service) {
    // Typecast the binder to the service's LocalBinder class
    serviceBinder = (BtleService.LocalBinder) service;

    Log.i("freefall","Service Connected");

    retrieveBoard();
    }

    @Override
    public void onServiceDisconnected(ComponentName componentName) {

    }


  • public void retrieveBoard() {
    final BluetoothManager btManager=
    (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    final BluetoothDevice remoteDevice=
    btManager.getAdapter().getRemoteDevice(MW_MAC_ADDRESS);

    // Create a MetaWear board object for the Bluetooth Device
    board= serviceBinder.getMetaWearBoard(remoteDevice);

    board.connectAsync().continueWith(new Continuation<Void, Void>() {
    @Override
    public Void then(Task<Void> task) throws Exception {
    if (task.isFaulted()) {
    Log.i("freefall", "Failed to connect");
    } else {
    Log.i("freefall", "Connected");
    }
    led = board.getModule(Led.class);
    led.editPattern(Led.Color.BLUE)
    .riseTime((short) 0)
    .pulseDuration((short) 1000)
    .repeatCount((byte) 5)
    .highTime((short) 500)
    .highIntensity((byte) 16)
    .lowIntensity((byte) 16)
    .commit();
    led.play();

    return null;
    }
    });
    }
  • Try adjusting the connection parameters for high frequency streaming:
This discussion has been closed.