Configuration Example
This example shows how to expose persistent configuration values through ArmorLink.
Configuration values are automatically:
- Stored on the module
- Restored after reboot
- Displayed in the ArmorLink App
- Editable without recompiling firmware
For the conceptual overview, see Configuration.
What This Example Does
This module exposes several configuration values:
- LED brightness
- Animation speed
- Audio enabled
- Firmware information
The ArmorLink App automatically creates the appropriate user interface.
Complete Example
#include <ArmorLink.h>
ArmorLinkModule module(
"Arc Reactor",
ArmorLinkModuleType::Generic
);
int brightness = 120;
float animationSpeed = 1.0f;
bool audioEnabled = true;
void applyBrightness(int value)
{
ArmorLink.info("Brightness changed");
}
void setup()
{
Serial.begin(115200);
delay(500);
module.config()
.addInt("brightness", &brightness, 120)
.label("Brightness")
.description("LED brightness")
.section("Lighting")
.range(0, 255)
.step(1)
.onIntChange([](int value)
{
applyBrightness(value);
});
module.config()
.addFloat("animationSpeed", &animationSpeed, 1.0f)
.label("Animation Speed")
.description("Animation speed multiplier")
.section("Lighting")
.range(0.1f, 5.0f)
.step(0.1f);
module.config()
.addBool("audioEnabled", &audioEnabled, true)
.label("Audio Enabled")
.section("Audio");
module.config()
.addReadonly("firmwareVersion", "0.1.0")
.label("Firmware Version")
.section("System");
ArmorLinkOptions options;
options.enableEspNow = true;
ArmorLink.begin(module, options);
}
void loop()
{
ArmorLink.loop();
}
Integer Configuration
Integer values are useful for:
- Brightness
- Servo positions
- Thresholds
- Volume levels
Example:
module.config()
.addInt("brightness", &brightness, 120)
.label("Brightness")
.range(0, 255)
.step(1);
Float Configuration
Float values are useful for:
- Animation speeds
- Calibration values
- Sensor factors
- Voltage offsets
Example:
module.config()
.addFloat("animationSpeed", &animationSpeed, 1.0f)
.label("Animation Speed")
.range(0.1f, 5.0f)
.step(0.1f);
Boolean Configuration
Boolean values automatically appear as switches in the ArmorLink App.
Example:
module.config()
.addBool("audioEnabled", &audioEnabled, true)
.label("Audio Enabled");
Readonly Values
Readonly fields provide information but cannot be modified.
Example:
module.config()
.addReadonly("firmwareVersion", "0.1.0")
.label("Firmware Version");
Typical use cases:
- Firmware version
- Build date
- Hardware revision
- Calibration status
Organizing Configuration
Configuration values can be grouped into sections.
Example:
.section("Lighting")
.section("Audio")
.section("System")
The ArmorLink App automatically groups fields by section.
Validation
Validation metadata helps the App present sensible controls.
Example:
.range(0, 255)
.step(1)
Example:
.range(0.1f, 5.0f)
.step(0.1f)
This does not replace application-side validation but improves the user experience.
Reacting to Changes
Configuration values can execute callbacks when modified.
Example:
.onIntChange([](int value)
{
applyBrightness(value);
});
Flow:
User changes value
|
v
Module receives update
|
v
Value stored
|
v
Callback executes
Changes take effect immediately.
No reboot is required.
Persistence
Configuration values are automatically persisted by ArmorLink.
module.config()
.addInt("brightness", &brightness, 120);
No additional storage code is required.
Values automatically survive:
- Reboots
- Power cycles
- Firmware restarts
Advanced Fields
Less frequently used values can be marked as advanced.
.advanced(true)
This helps keep the main UI clean while still exposing expert settings.
Example: Servo Calibration
int openPos = 90;
int closedPos = 10;
module.config()
.addInt("openPos", &openPos, 90)
.label("Open Position")
.section("Servo")
.range(0, 180);
module.config()
.addInt("closedPos", &closedPos, 10)
.label("Closed Position")
.section("Servo")
.range(0, 180);
Next Steps
Continue with: