Skip to main content

Button Command Sender

This example demonstrates one of the most common ArmorLink patterns:

A local button sends Commands into the ArmorLink network.

Button Press
|
v
sendCommand(...)
|
v
Gateway
|
v
Target Module

The button itself remains normal firmware logic.

ArmorLink is only responsible for transporting the Command.

Complete Example

#include <ArmorLink.h>

#define BUTTON_PIN 4

ArmorLinkModule module(
"Left Hand",
ArmorLinkModuleType::Hand
);

bool lastButtonState = HIGH;

void setup()
{
Serial.begin(115200);
delay(500);

pinMode(BUTTON_PIN, INPUT_PULLUP);

ArmorLinkOptions options;
options.enableEspNow = true;

ArmorLink.begin(module, options);
}

void loop()
{
ArmorLink.loop();

bool currentState = digitalRead(BUTTON_PIN);

if(lastButtonState == HIGH && currentState == LOW)
{
onButtonPressed();
}

lastButtonState = currentState;
}

void onButtonPressed()
{
ArmorLink.sendCommand(
"Helmet",
"Facemask",
"toggle"
);
}

Sending a Command

A Command contains three parts:

ArmorLink.sendCommand(
"Helmet",
"Facemask",
"toggle"
);
ValuePurpose
HelmetTarget Module
FacemaskEntity
toggleCommand

The target module receives the Command through the Gateway.

Matching Action

The receiving module exposes an Action:

module.actions()
.add("toggleFaceplate")
.label("Toggle Faceplate")
.command("Facemask", "toggle")
.onExecute([]{
toggleFaceplate();
});

When the Command arrives, ArmorLink executes the Action.

Sending Commands to the Gateway

Commands can also target the Gateway directly.

ArmorLink.sendCommand(
"Chest",
"BTN_L1",
"SINGLE_CLICK"
);

This is useful when the Gateway acts as a central controller.

Examples:

  • Sound control
  • Effect coordination
  • Global state changes
  • Command routing

Sending Broadcast Commands

Instead of targeting one module, a Command can be broadcast.

ArmorLink.broadcastCommand(
"Flaps",
"toggle"
);

Every module receives the Command.

Only modules with matching Actions react.

Example:

module.actions()
.add("toggleFlaps")
.label("Toggle Flaps")
.command("Flaps", "toggle")
.onExecute([]{
toggleFlaps();
});

Multiple Buttons

Different buttons can send different Commands.

void handleBtn1()
{
ArmorLink.sendCommand(
"Helmet",
"Facemask",
"toggle"
);
}

void handleBtn2()
{
ArmorLink.sendCommand(
"Back",
"Missile",
"open"
);
}

This allows a small controller module to operate many remote modules.

Local and Remote Behavior

A button can trigger local and remote behavior at the same time.

void onButtonPressed()
{
flashLed();

ArmorLink.sendCommand(
"Helmet",
"Facemask",
"toggle"
);
}

ArmorLink does not replace application logic.

It simply transports Commands.

Typical Use Cases

This pattern is commonly used for:

  • Hand controllers
  • Hidden suit buttons
  • Reed switches
  • Voice recognition modules
  • Gesture controllers
  • Sensor-triggered actions

Next Steps

Continue with: