Button Multi-Mode Control Scenario
Button Multi-Mode Control Scenario
Scenario Description
Implement multiple control modes through a single physical button: single-click to turn on the light, double-click to turn off the light, long-press for 2 seconds to switch mode, long-press for 5 seconds to restart the device.
Required Peripherals
| Peripheral | Type | Description |
|---|---|---|
| btn1 | GPIO_DIGITAL_INPUT_PULLUP(13) | Function button |
| relay1 | GPIO_DIGITAL_OUTPUT(12) | Light relay |
| led1 | GPIO_DIGITAL_OUTPUT(12) | Status indicator LED |
Complete Configuration Process
Method 1: Web Interface Configuration (Recommended)
This scenario requires first adding the button, relay, and status LED, then using peripheral execution rules to map single-click, double-click, long-press and other events to different actions.
Step 1: Configure Peripherals
Step 1: Open the Peripheral Management page
- Open a browser and navigate to the ESP32 IP address
- After logging in, click Peripheral Configuration in the left menu
Step 2: Add the Function Button
Click the Add Peripheral button
Fill in the configuration:
Field Value Description Peripheral ID btn1Function button Name Function ButtonDisplay name Peripheral Type GPIO Digital Input Pull-up (type: 13) Button input Pin Configuration 0Button connected to GPIO0 Initial State 0Default Click Save
💡 Tip: Connect one end of the button to GPIO and the other end to GND, using internal pull-up
Step 3: Add the Light Relay
Click the Add Peripheral button again
Fill in the configuration:
Field Value Description Peripheral ID relay1Light relay Name Light RelayDisplay name Peripheral Type GPIO Digital Output (type: 12) Relay control Pin Configuration 15IN connected to GPIO15 Initial State 0Default off Click Save
Step 4: Add the Status Indicator LED
Click the Add Peripheral button a third time
Fill in the configuration:
Field Value Description Peripheral ID led1Status indicator LED Name Status LEDDisplay name Peripheral Type GPIO Digital Output (type: 12) LED control Pin Configuration 2Onboard LED or external Initial State 0Default off Click Save
Step 2: Configure Peripheral Execution Rules
Rule 1: Single-click to Turn On Light
Switch to the Peripheral Execution Management tab
Click the Add Rule button
Fill in the basic configuration:
- Rule Name:
Single Click Light On - Report Data: ✅ Enabled
- Enable: ✅ Enabled
- Rule Name:
Configure the trigger:
- Trigger Type: Select Event Trigger
- Event ID: Select
button_click(button single-click) - Target Peripheral ID: Enter
btn1(specify the button)
Configure the action:
- Action Type: Select High Level
- Target Peripheral: Select
relay1
Click Save
Rule 2: Double-click to Turn Off Light
Create a rule, name:
Double Click Light OffTrigger configuration:
- Trigger Type: Select Event Trigger
- Event ID: Select
button_double_click(button double-click) - Target Peripheral ID: Enter
btn1
Action configuration:
- Action Type: Select Low Level
- Target Peripheral: Select
relay1
Click Save
Rule 3: Long-press 2 Seconds to Flash Indicator
Create a rule, name:
Long Press Mode SwitchTrigger configuration:
- Trigger Type: Select Event Trigger
- Event ID: Select
button_long_press_2s(long-press 2 seconds) - Target Peripheral ID: Enter
btn1
Action configuration:
- Action Type: Select Flash
- Target Peripheral: Select
led1 - Flash Interval:
200(200ms)
Click Save
Rule 4: Long-press 5 Seconds to Restart Device
Create a rule, name:
Long Press RestartTrigger configuration:
- Trigger Type: Select Event Trigger
- Event ID: Select
button_long_press_5s(long-press 5 seconds) - Target Peripheral ID: Enter
btn1
Action configuration:
- Action Type: Select System Restart
- Execution Delay:
500(delay 500ms to let preceding actions complete)
Click Save
💡 Tip:
- Button event priority: Press → 2s long-press → 5s long-press → 10s long-press
- System has built-in 50ms software debouncing
- Each phase does not interfere with others
Method 2: JSON Configuration File Import
Button Event Priority
Long-press events trigger progressively by time: Press → 2s long-press → 5s long-press → 10s long-press. Each phase does not interfere with others.
Precautions
- Specify Button:
triggerPeriphId: "btn1"ensures only the designated button is responded to - Built-in Debounce: System has built-in 50ms software debouncing
- Pull-up Mode: Connect one end of the button to GPIO and the other end to GND, using internal pull-up
