Skip to content

Example 3: LED Flowing Light ​

Experiment Overview ​

Use multiple GPIO output pins and a command-script action to turn LEDs on and off in sequence.

Hardware Wiring ​

Board LabelGPIO PinConnected Device
D1GPIO15LED1 (active low)
D2GPIO2LED2 (active low)
D3GPIO0LED3 (active low)
D4GPIO4LED4 (active low)

JSON Configuration Example ​

json
{
  "peripherals": [
    {
      "id": "flow_led1",
      "name": "Flow LED-1",
      "type": 12,
      "enabled": false,
      "pins": [15],
      "params": { "initialState": 1 }
    },
    {
      "id": "flow_led2",
      "name": "Flow LED-2",
      "type": 12,
      "enabled": false,
      "pins": [2],
      "params": { "initialState": 1 }
    },
    {
      "id": "flow_led3",
      "name": "Flow LED-3",
      "type": 12,
      "enabled": false,
      "pins": [0],
      "params": { "initialState": 1 }
    },
    {
      "id": "flow_led4",
      "name": "Flow LED-4",
      "type": 12,
      "enabled": false,
      "pins": [4],
      "params": { "initialState": 1 }
    }
  ]
}

Peripheral Execution Linkage ​

Scenario: Timed Running Light (Timer Trigger + Command Script) ​

Function: Run the rule every 5 seconds and switch LEDs every 300 ms inside the script

Web Interface Configuration Steps ​

Step 1: Create Rule

  1. Click Peripheral Execution in the left menu
  2. Click New Rule button
  3. Fill in basic configuration:
    • Rule Name: LED Running Light
    • Report Data: ❌ Disable
    • Enabled: ✅ Enable

Step 2: Configure Trigger

  1. Click Add Trigger button

  2. Fill in trigger configuration:

    FieldValueDescription
    Trigger TypeSelect Timer TriggerExecute at time intervals
    Timer ModeSelect Interval TimerExecute every X seconds
    Interval Seconds5Run one cycle every 5 seconds so executions do not overlap

Step 3: Configure Action

  1. Click Add Action button

  2. Fill in action configuration:

    FieldValueDescription
    Action TypeSelect Command ScriptExecute PERIPH/DELAY sequence
    Script ContentSee code block belowRunning light logic

Script Content:

PERIPH flow_led1 LOW
DELAY 300
PERIPH flow_led1 HIGH
PERIPH flow_led2 LOW
DELAY 300
PERIPH flow_led2 HIGH
PERIPH flow_led3 LOW
DELAY 300
PERIPH flow_led3 HIGH
PERIPH flow_led4 LOW
DELAY 300
PERIPH flow_led4 HIGH
  1. Click Save button

Execution Flow:

Triggered once every 5 seconds
  ↓
Turn on LED1 (LOW)
  ↓
Delay 300ms
  ↓
Turn off LED1 (HIGH)
  ↓
Turn on LED2 → Delay → Turn off
  ↓
Turn on LED3 → Delay → Turn off
  ↓
Turn on LED4 → Delay → Turn off
  ↓
Wait for the next cycle

Script Reference ​

CommandDescriptionExample
PERIPHControl peripheral levelPERIPH flow_led1 LOW
DELAYDelay (milliseconds)DELAY 300

Tip: Reorder the PERIPH commands for a back-and-forth pattern. Add rule triggers and actions when conditional linkage is required.

Notes ​

  1. Script Limit: One script is limited to 1024 characters and 50 commands
  2. Light Interval: This example uses 300 ms; adjust it as needed, but one DELAY cannot exceed 10 seconds
  3. GPIO0 Constraint: Do not pull GPIO0 LOW during boot, otherwise it enters download mode
  4. Extension: Reorder commands for a back-and-forth pattern; random values expand only in LOG and MQTT commands

FastBee | fastbee.cn