Skip to content

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 ​

PeripheralTypeDescription
btn1GPIO_DIGITAL_INPUT_PULLUP(13)Function button
relay1GPIO_DIGITAL_OUTPUT(12)Light relay
led1GPIO_DIGITAL_OUTPUT(12)Status indicator LED

Complete Configuration Process ​

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

  1. Open a browser and navigate to the ESP32 IP address
  2. After logging in, click Peripheral Configuration in the left menu

Step 2: Add the Function Button

  1. Click the Add Peripheral button

  2. Fill in the configuration:

    FieldValueDescription
    Peripheral IDbtn1Function button
    NameFunction ButtonDisplay name
    Peripheral TypeGPIO Digital Input Pull-up (type: 13)Button input
    Pin Configuration0Button connected to GPIO0
    Initial State0Default
  3. 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

  1. Click the Add Peripheral button again

  2. Fill in the configuration:

    FieldValueDescription
    Peripheral IDrelay1Light relay
    NameLight RelayDisplay name
    Peripheral TypeGPIO Digital Output (type: 12)Relay control
    Pin Configuration15IN connected to GPIO15
    Initial State0Default off
  3. Click Save

Step 4: Add the Status Indicator LED

  1. Click the Add Peripheral button a third time

  2. Fill in the configuration:

    FieldValueDescription
    Peripheral IDled1Status indicator LED
    NameStatus LEDDisplay name
    Peripheral TypeGPIO Digital Output (type: 12)LED control
    Pin Configuration2Onboard LED or external
    Initial State0Default off
  3. Click Save


Step 2: Configure Peripheral Execution Rules ​

Rule 1: Single-click to Turn On Light

  1. Click Peripheral Execution in the left menu

  2. Click the Add Rule button

  3. Fill in the basic configuration:

    • Rule Name: Single Click Light On
    • Report Data: ✅ Enabled
    • Enable: ✅ Enabled
  4. Configure the trigger:

    • Trigger Type: Select Event Trigger
    • Event ID: Select button_click (button single-click)
    • Target Peripheral ID: Enter btn1 (specify the button)
  5. Configure the action:

    • Action Type: Select High Level
    • Target Peripheral: Select relay1
  6. Click Save


Rule 2: Double-click to Turn Off Light

  1. Create a rule, name: Double Click Light Off

  2. Trigger configuration:

    • Trigger Type: Select Event Trigger
    • Event ID: Select button_double_click (button double-click)
    • Target Peripheral ID: Enter btn1
  3. Action configuration:

    • Action Type: Select Low Level
    • Target Peripheral: Select relay1
  4. Click Save


Rule 3: Long-press 2 Seconds to Flash Indicator

  1. Create a rule, name: Long Press Mode Switch

  2. Trigger configuration:

    • Trigger Type: Select Event Trigger
    • Event ID: Select button_long_press_2s (long-press 2 seconds)
    • Target Peripheral ID: Enter btn1
  3. Action configuration:

    • Action Type: Select Flash
    • Target Peripheral: Select led1
    • Flash Interval: 200 (200ms)
  4. Click Save


Rule 4: Long-press 5 Seconds to Restart Device

  1. Create a rule, name: Long Press Restart

  2. Trigger configuration:

    • Trigger Type: Select Event Trigger
    • Event ID: Select button_long_press_5s (long-press 5 seconds)
    • Target Peripheral ID: Enter btn1
  3. Action configuration:

    • Action Type: Select System Restart
    • Execution Delay: 500 (delay 500ms to let preceding actions complete)
  4. 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 ​

  1. Specify Button: triggerPeriphId: "btn1" ensures only the designated button is responded to
  2. Built-in Debounce: System has built-in 50ms software debouncing
  3. Pull-up Mode: Connect one end of the button to GPIO and the other end to GND, using internal pull-up

FastBee | fastbee.cn