The on-board flash memory can also be used to store MetaWear commands instead of sensor data. Recorded commands can be executed any time after being programmed with the functions in macro.h header file.

Recording Commands

To record commands:

  1. Call mbl_mw_macro_record to put the API in macro mode
  2. Use the MetaWear commands that you want programmed
  3. Exit macro mode with mbl_mw_macro_end_record

Macros can be set to run on boot by setting the exec_on_boot parameter with a non-zero value.

#include "metawear/core/macro.h"
#include "metawear/peripheral/led.h"

void setup_macro(MblMwMetaWearBoard* board) {
    static auto callback = [](void* context, MblMwMetaWearBoard* board, int32_t id) {
        cout << "Macro ID = " << id << endl;
    MblMwLedPattern pattern = { 16, 16, 0, 500, 0, 1000, 0, 5 };

    mbl_mw_macro_record(board, 1);
    mbl_mw_led_write_pattern(board, &pattern, MBL_MW_LED_COLOR_BLUE);
    mbl_mw_macro_end_record(board, nullptr, callback);

Erasing Macros

Erasing macros is done with the mbl_mw_macro_erase_all method. The erase operation will not occur until you disconnect from the board.