Gateway Button Panel
This example shows how a Gateway can act as a central button command processor.
A common setup is:
Left Hand Button
|
v
Gateway
|
v
Local Action or Broadcast Command
Hand Module
The hand module reads a local button and sends a Command to the Gateway.
#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.nodeName = "Left Hand";
options.enableGateway = false;
options.enableEspNow = true;
options.enableBle = false;
options.enableSerialLogging = true;
options.defaultLogTarget = "Chest";
ArmorLink.begin(module, options);
ArmorLink.info("Left Hand module started");
}
void loop()
{
ArmorLink.loop();
bool currentButtonState = digitalRead(BUTTON_PIN);
if (lastButtonState == HIGH && currentButtonState == LOW) {
handleButtonPress();
}
lastButtonState = currentButtonState;
}
void handleButtonPress()
{
ArmorLink.info("Left hand button pressed");
ArmorLink.sendCommand("Chest", "BTN_L1", "SINGLE_CLICK");
}
Gateway Module
The Gateway receives the Command and reacts through an Action.
#include <ArmorLink.h>
ArmorLinkModule chestModule(
"Chest",
ArmorLinkModuleType::Chest
);
void stopAudio()
{
ArmorLink.info("Stopping audio");
}
void setup()
{
Serial.begin(115200);
delay(500);
chestModule.actions()
.add("leftBtn1SingleClick")
.label("Left BTN1 Single Click")
.section("Buttons")
.command("BTN_L1", "SINGLE_CLICK")
.stylePrimary()
.onExecute([] {
stopAudio();
});
ArmorLinkOptions options;
options.nodeName = "Chest";
options.enableGateway = true;
options.enableEspNow = true;
options.enableBle = true;
options.enableSerialCommands = true;
options.enableSerialMenu = true;
options.enableSerialLogging = true;
options.bleName = "ArmorLink Chest";
ArmorLink.begin(chestModule, options);
ArmorLink.info("Chest Gateway started");
}
void loop()
{
ArmorLink.loop();
}
Broadcast From the Gateway
The Gateway can translate one incoming button command into a broadcast command.
chestModule.actions()
.add("leftBtn1DoubleClick")
.label("Left BTN1 Double Click")
.section("Buttons")
.command("BTN_L1", "DOUBLE_CLICK")
.onExecute([] {
ArmorLink.broadcastCommand("Lights", "toggle");
});
Any module with a matching Action can react:
module.actions()
.add("toggleLights")
.label("Toggle Lights")
.command("Lights", "toggle")
.onExecute([] {
toggleLights();
});
Multiple Button Actions
chestModule.actions()
.add("leftBtn1LongPress")
.label("Left BTN1 Long Press")
.section("Buttons")
.command("BTN_L1", "LONG_PRESS")
.styleDanger()
.confirm("Run shutdown effects?")
.onExecute([] {
ArmorLink.broadcastCommand("System", "shutdown_effects");
});
Use this pattern for glove buttons, hidden switches, magnetic reed switches and central suit controls.