PWM / DAC Actions
PWM / DAC Actions
Action Types
| Action | actionType | Description |
|---|---|---|
| ACTION_SET_PWM | 4 | Set PWM duty cycle |
| ACTION_SET_DAC | 5 | Set DAC output value |
Configuration Examples
Method 1: Web Interface Configuration (Recommended)
The peripheral execution page is shown below. When configuring PWM/DAC actions, verify the target peripheral, duty cycle range, and whether to use the trigger received value.
Example 1: Set PWM Duty Cycle (LED Dimming)
Scenario: Set LED brightness to 50% (duty cycle 128/255)
Configuration Steps:
Edit the rule in the Peripheral Execution Management page
Click the Add Action button
Fill in the action configuration:
Field Value Description Action Type Select Set PWM PWM output Target Peripheral Select led_pwmPWM output peripheral Duty Cycle Value 1288-bit resolution 0-255 Click the Save button
💡 Tip: Duty cycle range depends on the peripheral's configured pwmResolution: 8-bit→0~255, 12-bit→0~4095
Example 2: Use Received Value to Dynamically Set PWM
Scenario: Dynamically control motor speed based on platform-delivered value
Configuration Steps:
Edit the rule, add an action
Fill in:
- Action Type: Select Set PWM
- Target Peripheral: Select
motor_pwm - Use Received Value: ✅ Enabled
- Note: The value passed at trigger time will be used as the PWM value
Click Save
💡 Tip: When "Use Received Value" is enabled, the platform sending [{"id":"motor_pwm","value":"200"}] will directly set it as the PWM value
Example 3: Set DAC Output Value
Scenario: Set DAC output voltage (ESP32 only supports GPIO25/26)
Configuration Steps:
Edit the rule, add an action
Fill in:
- Action Type: Select Set DAC
- Target Peripheral: Select
dac1 - Output Value:
200(range 0-255, 8-bit resolution)
Click Save
💡 Tip: ESP32 DAC is 8-bit; values 0-255 correspond to voltage 0-3.3V
Method 2: JSON Configuration File Import
Compatible Peripheral Types
| Action | Compatible Peripheral type |
|---|---|
| ACTION_SET_PWM | GPIO_PWM_OUTPUT(17), PWM_SERVO(41) |
| ACTION_SET_DAC | DAC(27) |
Precautions
- PWM Range: Values exceeding the resolution range will be clamped to the maximum value
- DAC Pins: ESP32 only supports DAC output on GPIO 25/26
- Servo Control: PWM_SERVO peripheral sets the pulse width corresponding to the angle via ACTION_SET_PWM
