/* PCNT example -- Rotary Encoder This example code is in the Public Domain (or CC0 licensed, at your option.) Unless required by applicable law or agreed to in writing, this software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_log.h" #include "rotary_encoder.h" static const char *TAG = "example"; void app_main(void) { // Rotary encoder underlying device is represented by a PCNT unit in this example uint32_t pcnt_unit = 0; // Create rotary encoder instance rotary_encoder_config_t config = ROTARY_ENCODER_DEFAULT_CONFIG((rotary_encoder_dev_t)pcnt_unit, 14, 15); rotary_encoder_t *encoder = NULL; ESP_ERROR_CHECK(rotary_encoder_new_ec11(&config, &encoder)); // Filter out glitch (1us) ESP_ERROR_CHECK(encoder->set_glitch_filter(encoder, 1)); // Start encoder ESP_ERROR_CHECK(encoder->start(encoder)); // Report counter value while (1) { ESP_LOGI(TAG, "Encoder value: %d", encoder->get_counter_value(encoder)); vTaskDelay(pdMS_TO_TICKS(1000)); } }