Example 3: LED Flowing Light
About 2 min
Example 3: LED Flowing Light
Experiment Overview
Use multiple GPIO output pins to sequentially turn on and off LEDs via script actions, creating a running light effect. FastBee supports complex GPIO timing control through rule scripts.
Hardware Wiring
| Board Label | GPIO Pin | Connected Device |
|---|---|---|
| D1 | GPIO15 | LED1 (active low) |
| D2 | GPIO2 | LED2 (active low) |
| D3 | GPIO0 | LED3 (active low) |
| D4 | GPIO4 | LED4 (active low) |
JSON Configuration Example
{
"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: Light up the next LED every 200ms to create a flowing effect
Web Interface Configuration Steps
Step 1: Create Rule
- Click left menu Peripheral Configuration → Switch to Peripheral Execution Management tab
- Click New Rule button
- Fill in basic configuration:
- Rule Name:
LED Running Light - Report Data: ❌ Disable
- Enabled: ✅ Enable
- Rule Name:
Step 2: Configure Trigger
Click Add Trigger button
Fill in trigger configuration:
Field Value Description Trigger Type Select Timer Trigger Execute at time intervals Timer Mode Select Interval Timer Execute every X seconds Interval Seconds 0.2Execute every 0.2 seconds (200ms)
Step 3: Configure Action
Click Add Action button
Fill in action configuration:
Field Value Description Action Type Select Command Script Execute PERIPH/DELAY sequence Script Content See code block below Running 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- Click Save button
Execution Flow:
Triggered every 200ms
↓
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 next 200ms cycleScript Reference
| Command | Description | Example |
|---|---|---|
PERIPH | Control peripheral level | PERIPH flow_led1 LOW |
DELAY | Delay (milliseconds) | DELAY 300 |
💡 Tip: You can also use JavaScript scripts for more complex running light logic (e.g., back-and-forth, random lighting)
Notes
- Script Length Limit: Single-line script recommended not to exceed 256 characters
- Execution Interval: 200ms provides good visual effect, adjustable as needed
- GPIO0 Constraint: Do not pull GPIO0 LOW during boot, otherwise it enters download mode
- Extension: Modify the script to achieve back-and-forth running, random lighting effects
