2026-06-13 08:26:41 +03:00
2026-04-26 10:55:14 +03:00
2025-10-20 19:01:06 +04:00
2025-10-14 13:45:53 +03:00
2026-06-13 08:26:41 +03:00
2026-03-28 08:53:09 +03:00
2026-06-13 08:26:41 +03:00
2026-06-13 08:26:41 +03:00

ESP32 ESP-IDF component for AC dimmer 115V/400Hz

Wiki

EN | RU

Tested on

  1. ESP32 ESP-IDF v6.0.0

SAST Tools

PVS-Studio - static analyzer for C, C++, C#, and Java code.

Attention

  1. Supports frequency 400Hz only.
  2. For correct operation, please enable the following settings in the menuconfig:
GPIO_CTRL_FUNC_IN_IRAM
CONFIG_GPTIMER_ISR_HANDLER_IN_IRAM
CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM
CONFIG_GPTIMER_ISR_CACHE_SAFE

Using

In an existing project, run the following command to install the components:

cd ../your_project/components
git clone https://github.com/aZholtikov/zh_ac_dimmer

In the application, add the component:

#include "zh_ac_dimmer.h"

Examples

#include "zh_ac_dimmer.h"

void app_main(void)
{
    esp_log_level_set("zh_ac_dimmer", ESP_LOG_ERROR);
    zh_ac_dimmer_init_config_t config = ZH_AC_DIMMER_INIT_CONFIG_DEFAULT();
    config.zero_cross_gpio = GPIO_NUM_16;
    config.triac_gpio = GPIO_NUM_17;
    zh_ac_dimmer_init(&config);
    zh_ac_dimmer_start();
    uint8_t value = 0;
    for (uint8_t i = 0; i <= 100; ++i)
    {
        zh_ac_dimmer_set(i);
        zh_ac_dimmer_get(&value);
        printf("Dimmer value: %d.\n", value);
        vTaskDelay(100 / portTICK_PERIOD_MS);
    }
    for (uint8_t i = 100; i > 0; --i)
    {
        zh_ac_dimmer_set(i);
        zh_ac_dimmer_get(&value);
        printf("Dimmer value: %d.\n", value);
        vTaskDelay(100 / portTICK_PERIOD_MS);
    }
    zh_ac_dimmer_stop();
    zh_ac_dimmer_deinit();
}
S
Description
ESP32 ESP-IDF component for AC dimmer (phase-angle control).
Readme Apache-2.0
111 KiB
0 Stars 1 Watchers 0 Forks
Languages
C 99.1%
CMake 0.9%