{"id":3247,"date":"2024-12-20T19:08:52","date_gmt":"2024-12-20T11:08:52","guid":{"rendered":"https:\/\/saludpcb.com\/zh\/?p=3247"},"modified":"2025-09-26T06:15:57","modified_gmt":"2025-09-25T22:15:57","slug":"arduino-esp32-multi-function-key","status":"publish","type":"post","link":"https:\/\/saludpcb.com\/zh\/arduino-esp32-multi-function-key\/","title":{"rendered":"\u6253\u9020 AI \u6309\u9215 | Arduino ESP32 \u89e3\u9396 Multi-Function Key \u591a\u529f\u80fd\u6309\u9375\u64cd\u4f5c"},"content":{"rendered":"\n<hr class=\"wp-block-separator alignwide has-text-color has-palette-color-1-color has-alpha-channel-opacity has-palette-color-1-background-color has-background is-style-wide\"\/>\n\n\n\n<p><strong>Multi-Function Key\uff08\u591a\u529f\u80fd\u6309\u9375\uff09<\/strong>\u00a0\u662f\u73fe\u4ee3\u667a\u80fd\u8a2d\u5099\u4e2d\u7684\u4e00\u500b\u91cd\u8981\u7279\u6027\uff0c\u5b83\u4e0d\u50c5\u80fd\u57f7\u884c\u57fa\u672c\u7684\u958b\u95dc\u64cd\u4f5c\uff0c\u9084\u80fd\u6839\u64da\u4e0d\u540c\u7684\u9ede\u64ca\u65b9\u5f0f\u5be6\u73fe\u591a\u7a2e\u529f\u80fd\u3002\u4f7f\u7528\u00a0<strong>Arduino ESP32<\/strong>\uff0c\u4f60\u53ef\u4ee5\u8f15\u9b06\u6253\u9020\u4e00\u500b\u00a0<strong>Multi-Function Key<\/strong>\uff0c\u8b93\u4f60\u7684\u6309\u9215\u66f4\u52a0\u667a\u80fd\uff0c\u80fd\u5920\u652f\u6301\u77ed\u6309\u3001\u9577\u6309\u3001\u96d9\u64ca\u7b49\u591a\u7a2e\u4ea4\u4e92\u65b9\u5f0f\u3002\u9019\u7bc7\u6587\u7ae0\u5c07\u6559\u4f60\u5982\u4f55\u5229\u7528\u00a0<strong>Arduino ESP32<\/strong>\u00a0\u5be6\u73fe\u9019\u6a23\u7684\u00a0<strong>Multi-Function Key<\/strong>\uff0c\u4e26\u63a2\u7d22\u5b83\u7684\u61c9\u7528\u5834\u666f\u548c\u8a2d\u8a08\u539f\u7406\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/saludpcb.com\/zh\/wp-content\/uploads\/2024\/12\/Create-Your-AI-Button-with-Arduino-ESP32-Multi-Function-Key-Events-Made-Easy.jpg\" alt=\"Multi-Function Key\" class=\"wp-image-3255\" title=\"\" srcset=\"https:\/\/saludpcb.com\/zh\/wp-content\/uploads\/2024\/12\/Create-Your-AI-Button-with-Arduino-ESP32-Multi-Function-Key-Events-Made-Easy.jpg 1024w, https:\/\/saludpcb.com\/zh\/wp-content\/uploads\/2024\/12\/Create-Your-AI-Button-with-Arduino-ESP32-Multi-Function-Key-Events-Made-Easy-768x768.jpg 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>\u5167\u5bb9<\/h2><nav><ul><li class=\"\"><a href=\"#introduction\">\u7c21\u4ecb<\/a><\/li><li class=\"\"><a href=\"#\u4ec0\u9ebc\u662f-touch-sensor\uff1f\">\u4ec0\u9ebc\u662f Multi-Function Key\uff1f<\/a><\/li><li class=\"\"><a href=\"#why-use-dma-and-i-2-s-with-adc-on-esp-32\">\u958b\u767c\u74b0\u5883<\/a><\/li><li class=\"\"><a href=\"#\u5be6\u73fe\u591a\u529f\u80fd\u6309\u9375\u7684\u57fa\u672c\u539f\u7406\">\u5be6\u73fe\u591a\u529f\u80fd\u6309\u9375\u7684\u57fa\u672c\u539f\u7406<\/a><\/li><li class=\"\"><a href=\"#\u4ee3\u78bc\u5be6\u73fe\">\u7a0b\u5f0f\u78bc\u5be6\u73fe<\/a><\/li><li class=\"\"><a href=\"#\u548c\">\u7a0b\u5f0f\u78bc\u89e3\u8aaa<\/a><\/li><li class=\"\"><a href=\"#6\">\u8f38\u51fa<\/a><\/li><li class=\"\"><a href=\"#conclusion\">\u7d50\u8ad6<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"introduction\">\u7c21\u4ecb<\/h2>\n\n\n\n<p>\u7576\u6211\u5011\u8ac7\u8ad6\u00a0<strong>\u591a\u529f\u80fd\u6309\u9375\uff08Multi-Function Key\uff09<\/strong>\u00a0\u548c\u00a0<strong>\u4e8b\u4ef6\uff08Events\uff09<\/strong>\u00a0\u6642\uff0c\u4e3b\u8981\u6307\u7684\u662f\u901a\u904e\u4e0d\u540c\u7684\u6309\u9375\u64cd\u4f5c\uff08\u5982\u77ed\u6309\u3001\u9577\u6309\u3001\u96d9\u64ca\u7b49\uff09\u4f86\u89f8\u767c\u4e0d\u540c\u7684\u529f\u80fd\u6216\u884c\u70ba\u3002<strong>\u591a\u529f\u80fd\u6309\u9375<\/strong>\u00a0\u662f\u4e00\u7a2e\u8b93\u6309\u9215\u5177\u6709\u66f4\u591a\u64cd\u4f5c\u65b9\u5f0f\u7684\u8a2d\u8a08\uff0c\u800c\u00a0<strong>\u4e8b\u4ef6<\/strong>\u00a0\u662f\u9019\u4e9b\u64cd\u4f5c\u65b9\u5f0f\u6240\u89f8\u767c\u7684\u5177\u9ad4\u884c\u70ba\u6216\u53cd\u61c9\u3002\u901a\u8fc7\u9019\u7a2e\u8a2d\u8a08\uff0c\u7528\u6236\u53ef\u4ee5\u901a\u904e\u7c21\u55ae\u7684\u6309\u9375\u64cd\u4f5c\u4f86\u63a7\u5236\u66f4\u591a\u529f\u80fd\uff0c\u5f9e\u800c\u63d0\u5347\u8a2d\u5099\u7684\u667a\u80fd\u6027\u548c\u4ea4\u4e92\u6027\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u4ec0\u9ebc\u662f-touch-sensor\uff1f\">\u4ec0\u9ebc\u662f Multi-Function Key\uff1f<\/h2>\n\n\n\n<p>Multi-Function Key\uff08\u591a\u529f\u80fd\u6309\u9375\uff09\u662f\u6307\u4e00\u500b\u6309\u9375\uff0c\u901a\u904e\u4e0d\u540c\u7684\u9ede\u64ca\u65b9\u5f0f\u6216\u9577\u77ed\u6309\u7b49\u52d5\u4f5c\uff0c\u80fd\u5920\u5be6\u73fe\u4e0d\u540c\u7684\u529f\u80fd\u6216\u64cd\u4f5c\u3002\u4f8b\u5982\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u96d9\u64ca<\/strong>\uff1a\u89f8\u767c\u67d0\u4e00\u7279\u5b9a\u64cd\u4f5c<\/li>\n\n\n\n<li><strong>\u9577\u6309<\/strong>\uff1a\u555f\u52d5\u67d0\u7a2e\u529f\u80fd\u6216\u5207\u63db\u6a21\u5f0f<\/li>\n\n\n\n<li><strong>\u77ed\u6309<\/strong>\uff1a\u5feb\u901f\u57f7\u884c\u57fa\u672c\u64cd\u4f5c<\/li>\n<\/ul>\n\n\n\n<p>\u9019\u7a2e\u8a2d\u8a08\u8b93\u6309\u9375\u64c1\u6709\u591a\u7a2e\u53ef\u80fd\u6027\uff0c\u800c\u4e0d\u662f\u53ea\u7528\u4f86\u958b\u555f\u6216\u95dc\u9589\u67d0\u500b\u8a2d\u5099\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"why-use-dma-and-i-2-s-with-adc-on-esp-32\">\u958b\u767c\u74b0\u5883<\/h2>\n\n\n\n<p>\u5728\u958b\u59cb\u7de8\u7a0b\u4e4b\u524d\uff0c\u8acb\u78ba\u4fdd\u5df2\u5b8c\u6210\u4ee5\u4e0b\u6e96\u5099\u5de5\u4f5c\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5b89\u88dd <a href=\"https:\/\/www.arduino.cc\" target=\"_blank\" rel=\"noopener\">Arduino IDE<\/a> \u548c <a href=\"https:\/\/saludpcb.com\/zh\/quick-easy-steps-to-use-arduino-ide-for-esp32-ble\/\">ESP32<\/a> \u958b\u767c\u74b0\u5883\u3002<\/li>\n\n\n\n<li><a href=\"https:\/\/saludpcb.com\/zh\/esp32-devkit-module-pinout\/\">ESP32 \u958b\u767c\u677f<\/a>\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u5be6\u73fe\u591a\u529f\u80fd\u6309\u9375\u7684\u57fa\u672c\u539f\u7406\">\u5be6\u73fe\u591a\u529f\u80fd\u6309\u9375\u7684\u57fa\u672c\u539f\u7406<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6309\u9375\u884c\u70ba\u7684\u8b58\u5225<\/strong>\uff1a\u77ed\u6309\uff08Single Click\uff09\uff0c\u9577\u6309\uff08Long Press\uff09\uff0c\u96d9\u64ca\uff08Double Click\uff09\uff0c\u4e09\u64ca\uff08Triple Click\uff09\uff0c\u9023\u7e8c\u9ede\u64ca\u3002<\/li>\n\n\n\n<li><strong>\u6309\u9215\u9593\u9694\u6642\u9593<\/strong>\uff1a\u9019\u662f\u5224\u65b7\u9023\u64ca\u64cd\u4f5c\u662f\u5426\u70ba\u96d9\u64ca\u3001\u4e09\u64ca\u7b49\u7684\u95dc\u9375\u3002\u6bd4\u5982\u5169\u6b21\u6309\u4e0b\u4e4b\u9593\u7684\u6642\u9593\u8d85\u904e500\u6beb\u79d2\uff0c\u5c31\u53ef\u4ee5\u8a8d\u70ba\u662f\u4e00\u6b21\u55ae\u64ca\uff0c\u53cd\u4e4b\u5247\u8996\u70ba\u96d9\u64ca\u3002<\/li>\n\n\n\n<li><strong>\u6642\u9593\u7ba1\u7406\u8207\u5224\u65b7\u908f\u8f2f<\/strong>\uff1a\u70ba\u4e86\u5340\u5206\u9019\u4e9b\u884c\u70ba\uff0c\u6642\u9593\u662f\u95dc\u9375\u7684\u56e0\u7d20\u3002\u5177\u9ad4\u4f86\u8aaa\uff0c\u6309\u9215\u7684<strong>\u6309\u4e0b\u6642\u9593<\/strong>\u3001<strong>\u91cb\u653e\u6642\u9593<\/strong>\u4ee5\u53ca<strong>\u6309\u9215\u4e4b\u9593\u7684\u9593\u9694\u6642\u9593<\/strong>\u90fd\u9700\u8981\u9032\u884c\u7ba1\u7406\u3002<\/li>\n\n\n\n<li><strong>\u9632\u6296\u8207\u53bb\u566a<\/strong> : \u6309\u9215\u7684\u7269\u7406\u7d50\u69cb\u53ef\u80fd\u6703\u5c0e\u81f4\u6309\u9375\u8f38\u5165\u5728\u6309\u4e0b\u6216\u91cb\u653e\u6642\u7522\u751f\u4e00\u4e9b\u201c\u6296\u52d5\u201d\uff08\u5373\u77ed\u6642\u9593\u5167\u7684\u591a\u6b21\u958b\u95dc\u5207\u63db\uff09\u3002\u9019\u4e9b\u6296\u52d5\u53ef\u80fd\u6703\u88ab\u8aa4\u8b58\u5225\u70ba\u984d\u5916\u7684\u6309\u9215\u4e8b\u4ef6\uff0c\u5f9e\u800c\u5c0e\u81f4\u932f\u8aa4\u7684\u53cd\u61c9\u3002\u56e0\u6b64\uff0c\u9700\u8981\u5728\u786c\u9ad4\u548c\u8edf\u9ad4\u4e2d\u9032\u884c\u9632\u6296\u8655\u7406\u3002<\/li>\n\n\n\n<li><strong>\u786c\u9ad4\u4e2d\u65b7\u8207\u8f2a\u8a62<\/strong> : \u53ef\u7528\u5169\u7a2e\u5e38\u898b\u7684\u65b9\u6cd5\u4f86\u6aa2\u6e2c\u6309\u9215\u4e8b\u4ef6\u3002<\/li>\n\n\n\n<li><strong>\u4e8b\u4ef6\u8655\u7406<\/strong> : \u4e00\u65e6\u6309\u9375\u884c\u70ba\u88ab\u8b58\u5225\uff0c\u63a5\u4e0b\u4f86\u7684\u4efb\u52d9\u662f\u8655\u7406\u9019\u4e9b\u4e8b\u4ef6\u3002\u9019\u901a\u5e38\u6d89\u4e86 <strong>\u4e8b\u4ef6\u5206\u985e<\/strong>\uff0c\u5982\u55ae\u64ca\u3001\u96d9\u64ca\u3001\u9577\u6309\u7b49\uff0c\u7cfb\u7d71\u5c07\u5c0d\u4e8b\u4ef6\u9032\u884c\u5206\u985e\u4e26\u6c7a\u5b9a\u5c0d\u61c9\u7684\u64cd\u4f5c\u3002<strong>\u89f8\u767c\u76f8\u61c9\u64cd\u4f5c<\/strong>\uff0c\u6bcf\u7a2e\u6309\u9215\u4e8b\u4ef6\u90fd\u6703\u5c0d\u61c9\u4e00\u500b\u6216\u591a\u500b\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c\u77ed\u6309\u53ef\u80fd\u89f8\u767c\u71c8\u5149\u958b\u95dc\uff0c\u800c\u9577\u6309\u53ef\u80fd\u555f\u52d5\u67d0\u500b\u6a21\u5f0f\uff0c\u96d9\u64ca\u53ef\u80fd\u7528\u4f86\u8abf\u6574\u97f3\u91cf\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u4ee3\u78bc\u5be6\u73fe\">\u7a0b\u5f0f\u78bc\u5be6\u73fe<\/h2>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7a0b\u5f0f\u78bc\u7684\u7bc4\u4f8b\uff0c\u793a\u7bc4\u5982\u4f55\u4f7f\u7528 Arduino \u548c ESP32 \u64b0\u5beb\u7a0b\u5f0f\uff0c\u8b93\u6309\u9215\u5be6\u73fe\u4e0d\u540c\u529f\u80fd\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">#define BUTTON_PIN 2  \/\/ Define the pin connected to the button\n\n\/\/ Enumeration for different button events\nenum ButtonEvent { NONE, SINGLE_CLICK, DOUBLE_CLICK, TRIPLE_CLICK, LONG_PRESS };\n\n\/\/ Volatile variables to store the current event and button states\nvolatile ButtonEvent currentEvent = NONE; \/\/ Current button event\nvolatile unsigned long lastPressTime = 0; \/\/ Time when the button was last pressed\nvolatile unsigned long pressDuration = 0; \/\/ Duration the button was held\nvolatile int clickCount = 0; \/\/ Number of consecutive clicks\n\n\/\/ Timing thresholds\nunsigned long debounceTime = 50; \/\/ Debounce time to prevent false triggers (50 ms)\nunsigned long longPressThreshold = 1000; \/\/ Threshold for a long press (1000 ms)\nunsigned long clickTimeout = 300; \/\/ Time window for detecting double\/triple clicks (300 ms)\n\n\/\/ Interrupt service routine for handling button press and release\nvoid IRAM_ATTR handleButtonInterrupt() {\n    static unsigned long lastInterruptTime = 0; \/\/ To track the last interrupt time\n    unsigned long interruptTime = millis(); \/\/ Get the current system time\n\n    if (interruptTime - lastInterruptTime > debounceTime) { \/\/ Debounce check\n        if (digitalRead(BUTTON_PIN) == LOW) { \/\/ Button is pressed (LOW due to INPUT_PULLUP)\n            lastPressTime = interruptTime; \/\/ Record the press time\n        } else { \/\/ Button is released\n            pressDuration = interruptTime - lastPressTime; \/\/ Calculate the duration of the press\n\n            if (pressDuration >= longPressThreshold) { \/\/ Check if it is a long press\n                currentEvent = LONG_PRESS; \/\/ Set the event to LONG_PRESS\n            } else {\n                clickCount++; \/\/ Increment the click count for short presses\n            }\n        }\n    }\n    lastInterruptTime = interruptTime; \/\/ Update the last interrupt time\n}\n\nvoid setup() {\n    pinMode(BUTTON_PIN, INPUT_PULLUP); \/\/ Set button pin as input with an internal pull-up resistor\n    attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), handleButtonInterrupt, CHANGE); \n    \/\/ Attach an interrupt to the button pin to handle both press and release events\n    Serial.begin(115200); \/\/ Initialize serial communication for debugging\n}\n\nvoid loop() {\n    static unsigned long lastCheckTime = 0;\n\n    \/\/ Check if click events need to be processed\n    if (millis() - lastPressTime > clickTimeout &amp;&amp; clickCount > 0) {\n        switch (clickCount) {\n            case 1: currentEvent = SINGLE_CLICK; break; \/\/ Single click\n            case 2: currentEvent = DOUBLE_CLICK; break; \/\/ Double click\n            case 3: currentEvent = TRIPLE_CLICK; break; \/\/ Triple click\n        }\n        clickCount = 0; \/\/ Reset the click count\n    }\n\n    \/\/ Print the current event\n    if (currentEvent != NONE) {\n        printEvent(currentEvent); \/\/ Print the detected event\n        currentEvent = NONE; \/\/ Reset the event after processing\n    }\n}\n\n\/\/ Function to print the detected button event to the Serial Monitor\nvoid printEvent(ButtonEvent event) {\n    switch (event) {\n        case SINGLE_CLICK: Serial.println(\"Single Click\"); break;\n        case DOUBLE_CLICK: Serial.println(\"Double Click\"); break;\n        case TRIPLE_CLICK: Serial.println(\"Triple Click\"); break;\n        case LONG_PRESS: Serial.println(\"Long Press\"); break;\n        case NONE: break; \/\/ No event to process\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u548c\">\u7a0b\u5f0f\u78bc\u89e3\u8aaa<\/h2>\n\n\n\n<p><strong>\u5b9a\u7fa9\u6309\u9215\u5f15\u8173\u548c\u4e8b\u4ef6\u985e\u578b<\/strong> <code>ButtonEvent<\/code>\u00a0\u679a\u8209\u5305\u542b\u4e86\u4e0d\u540c\u7684\u4e8b\u4ef6\u985e\u578b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>NONE<\/code>\uff08\u7121\u4e8b\u4ef6\uff09<\/li>\n\n\n\n<li><code>SINGLE_CLICK<\/code>\uff08\u55ae\u64ca\uff09<\/li>\n\n\n\n<li><code>DOUBLE_CLICK<\/code>\uff08\u96d9\u64ca\uff09<\/li>\n\n\n\n<li><code>TRIPLE_CLICK<\/code>\uff08\u4e09\u64ca<\/li>\n\n\n\n<li><code>LONG_PRESS<\/code>\uff08\u9577\u6309\uff09<\/li>\n<\/ul>\n\n\n\n<p><strong>\u5168\u5c40\u8b8a\u6578\u5b9a\u7fa9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>currentEvent<\/code>\u00a0\u7528\u4f86\u5132\u5b58\u7576\u524d\u7684\u6309\u9215\u4e8b\u4ef6\u3002<\/li>\n\n\n\n<li><code>lastPressTime<\/code>\u00a0\u548c\u00a0<code>pressDuration<\/code>\u00a0\u7528\u4f86\u8ffd\u8e64\u6309\u4e0b\u6309\u9215\u7684\u6642\u9593\uff0c\u4ee5\u4fbf\u8b58\u5225\u9577\u6309\u548c\u77ed\u6309\u3002<\/li>\n\n\n\n<li><code>clickCount<\/code>\u00a0\u7528\u4f86\u8a08\u7b97\u6309\u9215\u88ab\u9ede\u64ca\u7684\u6b21\u6578\u3002<\/li>\n\n\n\n<li><code>debounceTime<\/code>\u00a0\u7528\u65bc\u9632\u6b62\u6309\u9215\u6296\u52d5\u5f15\u8d77\u8aa4\u89f8\u3002<\/li>\n\n\n\n<li><code>longPressThreshold<\/code>\u00a0\u8a2d\u7f6e\u9577\u6309\u7684\u6642\u9593\u95be\u503c\uff08\u6b64\u8655\u662f 1000 \u6beb\u79d2\uff0c\u5373 1 \u79d2\uff09\u3002<\/li>\n\n\n\n<li><code>clickTimeout<\/code>\u00a0\u8a2d\u5b9a\u96d9\u64ca\u6216\u4e09\u64ca\u7684\u6642\u9593\u7a97\u53e3\uff0c\u82e5\u6309\u4e0b\u4e4b\u9593\u7684\u6642\u9593\u5c0f\u65bc 300 \u6beb\u79d2\uff0c\u5247\u8a8d\u70ba\u662f\u96d9\u64ca\u6216\u4e09\u64ca\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u4e2d\u65b7\u8655\u7406\u51fd\u6578<\/strong>\u00a0<code>handleButtonInterrupt()<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>millis()<\/code>\u00a0\u7528\u65bc\u7372\u53d6\u7576\u524d\u7684\u7cfb\u7d71\u6642\u9593\uff08\u4ee5\u6beb\u79d2\u70ba\u55ae\u4f4d\uff09\u3002<\/li>\n\n\n\n<li>\u9632\u6296\u8655\u7406\uff1a\u5982\u679c\u6309\u9215\u6309\u4e0b\u6216\u91cb\u653e\u7684\u9593\u9694\u6642\u9593\u5c0f\u65bc\u00a0<code>debounceTime<\/code>\uff0c\u5247\u5ffd\u7565\u9019\u6b21\u4e8b\u4ef6\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u6309\u9215\u88ab\u6309\u4e0b\uff0c\u8a18\u9304\u6309\u4e0b\u6642\u9593 (<code>lastPressTime<\/code>)\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u6309\u9215\u88ab\u91cb\u653e\uff0c\u8a08\u7b97\u6309\u4e0b\u7684\u6301\u7e8c\u6642\u9593\u00a0<code>pressDuration<\/code>\uff0c\u4e26\u6839\u64da\u6301\u7e8c\u6642\u9593\u4f86\u8b58\u5225\u662f\u5426\u70ba\u9577\u6309\u3002\u5982\u679c\u4e0d\u662f\u9577\u6309\uff0c\u5247\u8a08\u7b97\u6309\u4e0b\u7684\u6b21\u6578\uff08\u9ede\u64ca\u6b21\u6578\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u521d\u59cb\u5316\u8a2d\u7f6e<\/strong>\u5728\u00a0<code>setup()<\/code>\u00a0\u51fd\u6578\u4e2d\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8a2d\u5b9a\u6309\u9215\u5f15\u8173\u70ba\u8f38\u5165\uff0c\u4e26\u555f\u7528\u5167\u90e8\u4e0a\u62c9\u96fb\u963b\u3002<\/li>\n\n\n\n<li><code>attachInterrupt()<\/code>\u00a0\u7528\u4f86\u5c07\u6309\u9215\u72c0\u614b\u8b8a\u5316\u6642\u7684\u4e2d\u65b7\u8207\u00a0<code>handleButtonInterrupt<\/code>\u00a0\u51fd\u6578\u7d81\u5b9a\u3002<\/li>\n\n\n\n<li>\u521d\u59cb\u5316\u5e8f\u5217\u901a\u8a0a\uff0c\u4ee5\u4fbf\u5728\u7d42\u7aef\u6253\u5370\u6309\u9215\u4e8b\u4ef6\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u4e3b\u5faa\u74b0\u8655\u7406<\/strong><code> loop()<\/code>\u00a0\u51fd\u6578\u662f Arduino \u7684\u4e3b\u5faa\u74b0\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5224\u65b7\u00a0<code>clickCount<\/code>\uff08\u6309\u9215\u88ab\u9ede\u64ca\u7684\u6b21\u6578\uff09\u662f\u5426\u9054\u5230\u96d9\u64ca\u6216\u4e09\u64ca\u7684\u6642\u9593\u7a97\u53e3\uff08<code>clickTimeout<\/code>\uff09\u3002\u82e5\u9054\u5230\u6642\u9593\u9650\u5236\uff0c\u5247\u6839\u64da\u00a0<code>clickCount<\/code>\u00a0\u8a2d\u5b9a\u4e8b\u4ef6\u985e\u578b\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528\u00a0<code>printEvent()<\/code>\u00a0\u51fd\u6578\u6253\u5370\u6309\u9215\u4e8b\u4ef6\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"6\">\u8f38\u51fa<\/h2>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u4e00\u6bb5\u4e32\u5217\u76e3\u8996\u5668\u7684\u53ef\u80fd\u986f\u793a\u8f38\u51fa\uff0c\u6a21\u64ec\u591a\u7a2e\u6309\u9375\u4e8b\u4ef6\u7684\u89f8\u767c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">Single Click\nDouble Click\nTriple Click\nLong Press\nSingle Click<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">\u7d50\u8ad6<\/h2>\n\n\n\n<p>\u4f7f\u7528 Arduino ESP32\uff0c\u4f60\u53ef\u4ee5\u8f15\u9b06\u8a2d\u8a08\u548c\u5be6\u73fe\u4e00\u500b\u591a\u529f\u80fd\u6309\u9215\uff0c\u4e26\u8b93\u4f60\u7684\u8a2d\u5099\u64c1\u6709\u66f4\u591a\u529f\u80fd\u548c\u667a\u80fd\u64cd\u4f5c\u3002\u9019\u6a23\u7684\u8a2d\u8a08\u4e0d\u50c5\u589e\u52a0\u4e86\u4f7f\u7528\u6a02\u8da3\uff0c\u9084\u8b93\u5275\u610f\u8207\u5be6\u73fe\u8b8a\u5f97\u66f4\u52a0\u6709\u50f9\u503c\uff01\u5e0c\u671b\u9019\u7bc7\u6587\u7ae0\u80fd\u5e6b\u52a9\u4f60\u6210\u529f\u6253\u9020\u5c6c\u65bc\u81ea\u5df1\u7684 AI \u6309\u9215\u3002\u5f0f\u61c9\u7528\u4e2d\u3002\u900f\u904e\u9019\u7a2e\u65b9\u6cd5\uff0c\u6211\u5011\u80fd\u5920\u5be6\u73fe\u7a69\u5b9a\u7684\u6309\u9375\u8f38\u5165\uff0c\u63d0\u5347\u7cfb\u7d71\u7684\u7a69\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator alignwide has-text-color has-palette-color-1-color has-alpha-channel-opacity has-palette-color-1-background-color has-background is-style-wide\"\/>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Multi-Function Key\uff08\u591a\u529f\u80fd\u6309\u9375\uff09\u00a0\u662f\u73fe\u4ee3\u667a\u80fd\u8a2d\u5099\u4e2d\u7684\u4e00\u500b\u91cd\u8981\u7279\u6027\uff0c\u5b83\u4e0d\u50c5\u80fd\u57f7\u884c\u57fa\u672c\u7684\u958b\u95dc\u64cd\u4f5c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3256,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,53,83],"tags":[61,27,63,20,60,10,64,11,62],"class_list":["post-3247","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-module","category-esp32","category-featured","tag-bluetooth","tag-c","tag-firmware","tag-hardware","tag-iot","tag-mcu","tag-module","tag-tutorial","tag-wifi"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/posts\/3247","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/comments?post=3247"}],"version-history":[{"count":9,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/posts\/3247\/revisions"}],"predecessor-version":[{"id":3258,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/posts\/3247\/revisions\/3258"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/media\/3256"}],"wp:attachment":[{"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/media?parent=3247"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/categories?post=3247"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/tags?post=3247"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}