{"id":804,"date":"2022-12-19T17:58:18","date_gmt":"2022-12-19T09:58:18","guid":{"rendered":"http:\/\/wordpress.loc\/?p=804"},"modified":"2022-12-19T17:58:37","modified_gmt":"2022-12-19T09:58:37","slug":"esp32_ch1-44","status":"publish","type":"post","link":"https:\/\/www.nmking.io\/index.php\/2022\/12\/19\/804\/","title":{"rendered":"ESP32\u4e2d\u65b7\u7528\u6cd5 attachInterrupt"},"content":{"rendered":"\n<figure class=\"wp-block-pullquote\"><blockquote><p>\u7576\u6211\u5011\u4f7f\u7528ESP32\u6642\uff0c\u53ef\u4ee5\u50cf\u50b3\u7d71Arduino UNO\u4f7f\u7528\u4e2d\u65b7\u8a9e\u6cd5<br>\u4e2d\u65b7(Interrupt)\u9019\u500b\u529f\u80fd\uff0c\u985e\u4f3c\u6211\u5011\u4ee5\u524d\u5bebC#\u6642\u7684Callback\uff0c\u4e5f\u5c31\u662f\u7269\u4ef6\u5c0e\u5411\u88e1\u9762\u7684\u4e8b\u4ef6(Event)\u9a45\u52d5\uff0c\u7576\u7279\u5b9a\u4e8b\u4ef6\u767c\u751f\u6642\uff0c\u6211\u5011\u518d\u53bb\u8655\u7406\u9019\u4ef6\u4e8b\u6240\u5c0d\u61c9\u7684\u529f\u80fdFunction\u3002<\/p><\/blockquote><\/figure>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u6211\u7684ESP32\u5be6\u505a\u66f8\u7c4d\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.nmking.io\/index.php\/2022\/11\/10\/esp32_ch1-2\/\" target=\"_blank\">\u6211\u51fa\u66f8\u4e86 ESP32 \u7269\u806f\u7db2\u5c08\u984c<\/a><br>\u535a\u5ba2\u4f86\u7db2\u5740\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.books.com.tw\/products\/0010901195\" target=\"_blank\">https:\/\/www.books.com.tw\/products\/0010901195<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<p>\u7576\u6211\u5011\u4f7f\u7528ESP32\u6642\uff0c\u53ef\u4ee5\u50cf\u50b3\u7d71Arduino UNO\u4f7f\u7528\u4e2d\u65b7\u8a9e\u6cd5<\/p>\n\n\n\n<p>\u4e2d\u65b7(Interrupt)\u9019\u500b\u529f\u80fd\uff0c\u985e\u4f3c\u6211\u5011\u4ee5\u524d\u5bebC#\u6642\u7684Callback\uff0c\u4e5f\u5c31\u662f\u7269\u4ef6\u5c0e\u5411\u88e1\u9762\u7684\u4e8b\u4ef6(Event)\u9a45\u52d5\uff0c\u7576\u7279\u5b9a\u4e8b\u4ef6\u767c\u751f\u6642\uff0c\u6211\u5011\u518d\u53bb\u8655\u7406\u9019\u4ef6\u4e8b\u6240\u5c0d\u61c9\u7684\u529f\u80fdFunction\u3002<\/p>\n\n\n\n<p>\u8209\u500b\u4f8b\u5b50\u4f86\u8aaa\uff0c\u5728\u9084\u6c92\u5b78\u7fd2\u5230\u4e2d\u65b7\u4ee5\u524d\uff0c\u6211\u5011\u7684\u4f86\u5ba2\u5831\u77e5\u6a5f(\u4eba\u9ad4\u611f\u6e2c\u5668+\u9304\u653e\u97f3\u6a5f)\u662f\u5229\u7528Loop\u5167\u7684\u4e0d\u65b7\u5075\u6e2c\uff0cdelay\u6642\u9593\u9084\u4e0d\u80fd\u592a\u9577\uff0c\u907f\u514d\u6c92\u5075\u6e2c\u5230\uff0c\u800c\u6c92\u6709\u89f8\u767c\u6b61\u8fce\u8a5e\uff0c\u4f46\u662f\u5982\u679c\u4f86\u5ba2\u5831\u77e5\u6a5f\u9084\u6709\u5176\u4ed6\u7528\u9014\u6642\uff0c\u4f8b\u5982\u5075\u6e2c\u5149\u654f\uff0c\u5c31\u5fc5\u9808\u4e5f\u5beb\u5728loop\u5167\uff0c\u9019\u6a23\u5169\u500b\u529f\u80fd\u5c31\u53ef\u80fd\u4e92\u76f8\u5e72\u64fe\uff0cdelay\u6642\u9593\u53ef\u80fd\u4e0d\u540c\u4e4b\u985e\u3002<\/p>\n\n\n\n<p>\u4e2d\u65b7\u7684\u529f\u80fd\u5247\u662f\u628a\u300c\u5075\u6e2c\u300d\u3001\u300c\u89f8\u767c\u300d\u7684\u90e8\u4efd\u5408\u4f75\u5728\u4e00\u8d77\uff0c\u4e26\u4e14\u53ef\u4ee5\u62c9\u51fa\u53bbLoop\u5916\uff0c\u8b93\u7cfb\u7d71\u4f86\u5e6b\u6211\u5011\u505a\uff0c\u4e0d\u904e\u5075\u6e2c\u53ea\u80fd\u6578\u4f4d\u5075\u6e2c\uff08HIGH\u6216LOW\uff09\uff0c\u53e6\u5916\u4e2d\u65b7\u5167\u4e0d\u653e\u7f6eDelay\uff0c\u8d8a\u7c21\u55ae\u8d8a\u597d\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u7bc4\u4f8b\u7a0b\u5f0f\uff0c\u53ef\u4ee5\u8b93ESP32\u4f9d\u64da\u8173\u4f4d14\u767c\u751f\u8b8a\u5316\u6642\uff0c\u6539\u8b8a\u8173\u4f4d2\u7684\u71c8\u865f\uff0c\u4f8b\u5982\u7576\u4eba\u9ad4\u611f\u6e2c\u5668\u767c\u751f\u8b8a\u5316\u6642\uff0c\u6703\u9ede\u4eaeLED\u71c8\u3002\u80fd\u5075\u6e2c\u7684\u8b8a\u5316\u6709\u56db\u7a2e\u985e\u578b<\/p>\n\n\n\n<p>LOW\uff1a\u72c0\u614b\u6210\u70baLOW\u5c31\u89f8\u767c<br>HIGH\uff1a\u72c0\u614b\u6210\u70baHIGH\u5c31\u89f8\u767c<br>CHANGE\uff1a\u72c0\u614b\u6539\u8b8a\u5c31\u89f8\u767c\uff0c\u4f8b\u5982LOW-&gt;HIGH\uff0c\u6216HIGH-&gt;LOW\u90fd\u7b97<br>RISING\uff1a\u72c0\u614b\u7531LOW-&gt;HIGH\u5c31\u89f8\u767c\uff0c\u53cd\u4e4b\u7121\u6548<br>FALLING\uff1a\u72c0\u614b\u7531HIGH-&gt;LOW\u5c31\u89f8\u767c\uff0c\u53cd\u4e4b\u7121\u6548<\/p>\n\n\n\n<p>\u6700\u5f8c\u7576\u8981\u53d6\u6d88\u4e2d\u65b7\u6642\uff0c\u53ef\u4ee5\u7528detachInterrupt(GPIOPin);\u4f86\u53d6\u6d88\u5373\u53ef<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int interruptPin = 14;  \/\/\u4e2d\u65b7\u8173\u4f4d\nint ledPin=2; \/\/LED\u8173\u4f4d\nint state = 0;   \/\/\u9810\u8a2dLED\u72c0\u614bLOW\nvoid setup() {\n  pinMode(ledPin, OUTPUT);  \n  pinMode(interruptPin, INPUT); \/\/\u4eba\u9ad4\u611f\u6e2c\u8f38\u5165\n  attachInterrupt(digitalPinToInterrupt(interruptPin), isr_Callback, CHANGE);  \n  \/\/CHANGE\uff1a\u72c0\u614b\u6539\u8b8a\u5c31\u89f8\u767c\n}\n \nvoid loop() {\n}\n \n\/\/\u4e2d\u65b7\u6642\u7684Callback\uff0c\u578b\u614b\u5ba3\u544a\u70baIRAM_ATTR\uff0c\u4ee3\u8868\u5c07\u6b64\u7a0b\u5f0f\u653e\u7f6eRAM\u4e2d\uff0c\u63d0\u6607\u6548\u80fd\u8207\u547d\u4e2d\u7387\nvoid IRAM_ATTR isr_Callback() {  \n  digitalWrite(ledPin, digitalRead(interruptPin));\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7576\u6211\u5011\u4f7f\u7528ESP32\u6642\uff0c\u53ef\u4ee5\u50cf\u50b3\u7d71Arduino UNO\u4f7f\u7528\u4e2d\u65b7\u8a9e\u6cd5\u4e2d\u65b7(Interrupt)\u9019\u500b\u529f\u80fd\uff0c\u985e\u4f3c\u6211 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-804","post","type-post","status-publish","format-standard","hentry","category-esp32"],"blocksy_meta":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/804","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/comments?post=804"}],"version-history":[{"count":1,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/804\/revisions"}],"predecessor-version":[{"id":805,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/804\/revisions\/805"}],"wp:attachment":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/media?parent=804"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/categories?post=804"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/tags?post=804"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}