触摸传感器使用顺序
1.初始化触摸传感器,
2.对触摸传感器和引脚进行配置,
3.启动FSM(有限状态机)
4.采集原始数据
5.卸载触摸传感器
初始化触摸传感器
![[Pasted image 20250519135238.png]]
FSM有限状态机
![[Pasted image 20250519135837.png]]
示例代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| #include <stdio.h> #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "driver/touch_sensor.h" #include "esp_log.h"
#define TAG "TOUCH"
void app_main(void) { touch_pad_init();
touch_pad_config(TOUCH_PAD_NUM11);
touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); touch_pad_fsm_start();
while (1) { uint32_t raw_data;
touch_pad_read_raw_data(TOUCH_PAD_NUM11, &raw_data);
ESP_LOGI(TAG, "原始值: %ld", raw_data);
vTaskDelay(pdMS_TO_TICKS(100)); }
touch_pad_fsm_stop();
touch_pad_deinit(); }
|