{"id":6924,"date":"2019-10-10T14:36:34","date_gmt":"2019-10-10T05:36:34","guid":{"rendered":"https:\/\/techclass.wfjydl.com\/?p=6924"},"modified":"2022-09-09T17:23:42","modified_gmt":"2022-09-09T09:23:42","slug":"arduino%e9%a2%84%e5%a4%84%e7%90%86%e5%99%a8%e6%8c%87%e4%bb%a4%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/techclass.wfjydl.com\/knowledge\/deviceplus\/how-tos\/arduino\/arduino-preprocessor-directives-tutorial","title":{"rendered":"Arduino\u9884\u5904\u7406\u5668\u6307\u4ee4\u6559\u7a0b"},"content":{"rendered":"<div class=\u201cthe_content_wrapper\u201d>\n\u8fd9\u7bc7\u6587\u7ae0\u6765\u6e90\u4e8e<a href=\"https:\/\/www.deviceplus.com\/\">DevicePlus.com<\/a>\u82f1\u8bed\u7f51\u7ad9\u7684\u7ffb\u8bd1\u7a3f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5827\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image001.jpg\" alt=\"arduino preprocessor\" width=\"700\" height=\"407\" srcset=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image001.jpg 700w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image001-300x174.jpg 300w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image001-251x146.jpg 251w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image001-50x29.jpg 50w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image001-129x75.jpg 129w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">\u5728<\/span><a href=\"https:\/\/techclass.wfjydl.com\/knowledge\/deviceplus\/how-tos\/arduino\/lightweight-arduino-library-for-rohm-sensor-evaluation-kit\" target=\"_blank\" rel=\"noopener noreferrer\"><b>\u9002\u7528\u4e8e极悦娱乐\u4f20\u611f\u5668\u8bc4\u4f30\u5957\u4ef6\u7684\u8f7b\u91cf\u7ea7Arduino\u5e93<\/b><\/a><span style=\"font-weight: 400;\">\u4e2d\uff0c\u6211\u4ecb\u7ecd\u4e86RohmMultiSensor\u2014\u2014\u5e2e\u60a8\u8f7b\u677e\u8fde\u63a5极悦娱乐\u4f20\u611f\u5668\u8bc4\u4f30\u5957\u4ef6\u591a\u4e2a\u4f20\u611f\u5668\u7684Arduino\u5e93\u3002\u8be5\u5e93\u7684\u6838\u5fc3\u7279\u5f81\u4e4b\u4e00\u5c31\u662f\u901a\u8fc7\u4ec5\u7f16\u8bd1\u4e0e\u6240\u9700\u4f20\u611f\u5668\u76f8\u5173\u7684\u5e93\u90e8\u5206\uff0c\u663e\u8457\u51cf\u5c0f\u7a0b\u5e8f\u7684\u5927\u5c0f\u3002\u8fd9\u610f\u5473\u7740\u5f53\u60a8\u4f7f\u7528\u8f83\u5c11\u7684\u4f20\u611f\u5668\u65f6\uff0c\u6574\u4f53\u7a0b\u5e8f\u5927\u5c0f\u548c\u5185\u5b58\u4f7f\u7528\u91cf\u4f1a\u51cf\u5c0f\u3002\u4f46\u662f\uff0c\u8fd9\u7a76\u7adf\u662f\u5982\u4f55\u5b9e\u73b0\u7684\u5462\uff1f\u5f53\u60a8<\/span><b><i>#include<\/i><\/b><span style=\"font-weight: 400;\">\u4e00\u4e2a\u5e93\u7136\u540e\u6309\u4e0b\u201cUpload\u201d\uff08\u4e0a\u4f20\uff09\u6309\u94ae\u4e4b\u540e\uff0c\u5e55\u540e\u7a76\u7adf\u4f1a\u53d1\u751f\u4ec0\u4e48\uff1f<\/span><\/p>\n<h2><b>\u786c\u4ef6<\/b><\/h2>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Arduino UNO<\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2><b>\u8f6f\u4ef6<\/b><\/h2>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Arduino IDE<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">\u51e0\u4e4e\u6240\u6709\u7528\u8fc7Arduino\u7684\u4eba\u90fd\u4f7f\u7528\u8fc7\u5e93\u3002\u8fd9\u5c31\u662fArduino\u7f16\u7a0b\u5bf9\u521d\u5b66\u8005\u6765\u8bf4\u5982\u6b64\u7b80\u5355\u7684\u539f\u56e0\u4e4b\u4e00\u2014\u2014\u60a8\u65e0\u9700\u6df1\u5165\u4e86\u89e3\u4f20\u611f\u5668\u7684\u5de5\u4f5c\u539f\u7406\uff1b\u5e93\u4f1a\u66ff\u60a8\u5b8c\u6210\u5927\u90e8\u5206\u5de5\u4f5c\u3002\u5c06\u4ee3\u7801\u5206\u6210\u5355\u72ec\u7684\u6587\u4ef6\u4e5f\u662f\u4e00\u79cd\u5f88\u597d\u7684\u7f16\u7a0b\u4e60\u60ef\u3002\u7ec4\u7ec7\u3001\u8c03\u8bd5\u548c\u7ef4\u62a4\u5355\u4e2a\u6587\u4ef6\u8981\u6bd4\u5904\u7406\u4e00\u5927\u5806\u4ee3\u7801\u5bb9\u6613\u5f97\u591a\u3002<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u60f3\u5fc5Arduino\u521d\u5b66\u8005\u90fd\u5df2\u7ecf\u719f\u6089\u4e86\u5c06\u5e93\u6dfb\u52a0\u5230\u4e3b\u7a0b\u5e8f\u4e2d\u7684<\/span><b><i>#include<\/i><\/b><span style=\"font-weight: 400;\">\u547d\u4ee4\u3002\u8981\u4e86\u89e3\u8fd9\u662f\u5982\u4f55\u5b9e\u73b0\u7684\uff0c\u6211\u4eec\u9996\u5148\u5e94\u5feb\u901f\u4e86\u89e3C\/C++\u6e90\u4ee3\u7801\u5982\u4f55\u7f16\u8bd1\u6210\u7a0b\u5e8f\u3002\u522b\u62c5\u5fc3\uff0c\u8fd9\u542c\u8d77\u6765\u6bd4\u8f83\u590d\u6742\uff0c\u5176\u5b9e\u5f88\u7b80\u5355\u3002\u6211\u4eec\u6765\u770b\u4e00\u4e0b\u7f16\u8bd1\u7684\u5de5\u4f5c\u539f\u7406\u3002<\/span><\/p>\n<h2><b>\u6309\u201c\u4e0a\u4f20\u201d\u4e4b\u540e<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">\u6211\u4eec\u5148\u505a\u4e00\u4e2a\u5feb\u901f\u5b9e\u9a8c\uff1a\u542f\u52a8Arduino IDE\uff0c\u6253\u5f00\u5176\u4e2d\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff08\u6bd4\u5982\u201cBlink\u201d\uff09\uff0c\u7136\u540e\u6309\u201cVerify\u201d\u6309\u94ae\u3002\u5047\u8bbe\u7a0b\u5e8f\u4e2d\u6ca1\u6709\u8bed\u6cd5\u9519\u8bef\uff0c\u5e95\u90e8\u7684\u63a7\u5236\u53f0\u5e94\u8be5\u4f1a\u6253\u5370\u51fa\u6709\u5173\u7a0b\u5e8f\u5927\u5c0f\u548c\u5185\u5b58\u7684\u4e00\u4e9b\u4fe1\u606f\u3002\u55ef\uff0c\u521a\u624d\u6211\u4eec\u6210\u529f\u5730\u5c06C++\u6e90\u4ee3\u7801\u7f16\u8bd1\u6210\u4e86\u4e8c\u8fdb\u5236\u6587\u4ef6\u3002\u5728\u7f16\u8bd1\u8fc7\u7a0b\u4e2d\u53d1\u751f\u4e86\u4ee5\u4e0b\u51e0\u4ef6\u4e8b\uff1a<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Arduino IDE\u6267\u884c\u4e86\u4e00\u79cd\u540d\u4e3a\u201c\u8bed\u6cd5\u68c0\u67e5\u201d\u7684\u64cd\u4f5c\uff0c\u4ee5\u786e\u4fdd\u60a8\u7f16\u5199\u7684\u7a0b\u5e8f\u662f\u771f\u6b63\u7684C\/C++\u6e90\u4ee3\u7801\u3002\u6b64\u65f6\uff0c\u5982\u679c\u53d1\u751f\u51fd\u6570\u62fc\u5199\u9519\u8bef\u6216\u5fd8\u8bb0\u5206\u53f7\uff0c\u90a3\u4e48\u7f16\u8bd1\u5c31\u4f1a\u505c\u6b62\u3002<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">\u8bed\u6cd5\u68c0\u67e5\u4e4b\u540e\uff0cArduino IDE\u4f1a\u542f\u52a8\u53e6\u4e00\u4e2a\u540d\u4e3a<\/span><i><span style=\"font-weight: 400;\">preprocessor<\/span><\/i><span style=\"font-weight: 400;\">\uff08\u9884\u5904\u7406\u5668\uff09\u7684\u7a0b\u5e8f\u3002\u8fd9\u662f\u4e00\u4e2a\u975e\u5e38\u7b80\u5355\u7684\u7a0b\u5e8f\uff0c\u5982\u679c\u6587\u4ef6\u662fC\/C++\u6e90\u4ee3\u7801\uff0c\u5b83\u4e0d\u4f1a\u600e\u4e48\u6837\u3002\u6211\u4eec\u7a0d\u540e\u4f1a\u8be6\u7ec6\u8ba8\u8bba\u8fd9\u4e00\u6b65\u9aa4\u3002\u90a3\u4e48\u73b0\u5728\u6211\u4eec\u5047\u8bbe\u7ed3\u679c\u662f\u4e00\u4e2a\u540d\u4e3a\u201c\u6269\u5c55\u6e90\u4ee3\u7801\u201d\u7684\u6587\u4ef6\u2014\u2014\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\u3002<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">\u7136\u540e\uff0c\u8be5\u6269\u5c55\u6e90\u4ee3\u7801\u88ab\u79fb\u4ea4\u7ed9\u53e6\u4e00\u4e2a\u540d\u4e3a<\/span><i><span style=\"font-weight: 400;\">compiler<\/span><\/i><span style=\"font-weight: 400;\">\uff08\u7f16\u8bd1\u5668\uff09\u7684\u7a0b\u5e8f\u3002\u8be5\u7f16\u8bd1\u5668\uff08\u5728Arduino IDE\u4e2d\u662f<\/span><i><span style=\"font-weight: 400;\">avr-gcc<\/span><\/i><span style=\"font-weight: 400;\">\uff09\u63a5\u6536\u6587\u672c\u6e90\uff0c\u5e76\u751f\u6210\u6c47\u7f16\u6587\u4ef6\u3002\u6c47\u7f16\u4e00\u79cd\u4eba\u7c7b\u53ef\u8bfb\u7684\u4f4e\u7ea7\u7f16\u7a0b\u8bed\u8a00\uff0c\u4f46\u662f\u66f4\u63a5\u8fd1\u673a\u5668\u4ee3\u7801\u2014\u2014\u9002\u7528\u4e8e\u7279\u5b9a\u5904\u7406\u5668\u7684\u6307\u4ee4\u3002\u8fd9\u91cc\u5c31\u662f\u60a8\u7f16\u5199\u7a0b\u5e8f\u4e4b\u524d\u5fc5\u987b\u9009\u62e9\u6b63\u786eArduino\u677f\u7684\u539f\u56e0\u2014\u2014\u4e0d\u540c\u7684\u5f00\u53d1\u677f\u5177\u6709\u4e0d\u540c\u7684\u5904\u7406\u5668\uff0c\u800c\u5904\u7406\u5668\u53c8\u5177\u6709\u4e0d\u540c\u7684\u6307\u4ee4\u96c6\u3002<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">\u5904\u7406\u60a8Arduino\u7a0b\u5e8f\u4e0b\u4e00\u4e2a\u7684\u7cfb\u7edf\u7a0b\u5e8f\u53eb\u505a<\/span><i><span style=\"font-weight: 400;\">assembler<\/span><\/i><span style=\"font-weight: 400;\">\uff08\u6c47\u7f16\u7a0b\u5e8f\uff09\u3002\u8be5\u7a0b\u5e8f\u4f1a\u751f\u6210\u4e00\u4e2a\u201c\u76ee\u6807\u6587\u4ef6\u201d\u3002\u8be5\u6587\u4ef6\u4e3b\u8981\u662f\u673a\u5668\u4ee3\u7801\uff0c\u4f46\u4e5f\u53ef\u4ee5\u5305\u542b\u9488\u5bf9\u5176\u4ed6\u76ee\u6807\u6587\u4ef6\u5bf9\u8c61\u7684\u201c\u5f15\u7528\u201d\u3002\u8fd9\u5141\u8bb8Arduino IDE\u201c\u9884\u7f16\u8bd1\u201d\u4e00\u4e9b\u7f16\u5199Arduino\u7a0b\u5e8f\u65f6\u4f1a\u59cb\u7ec8\u7528\u5230\u7684\u5e93\uff0c\u4ece\u800c\u4f7f\u6574\u4e2a\u8fc7\u7a0b\u66f4\u5feb\u3002<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">\u6700\u540e\u4e00\u4e2a\u9636\u6bb5\u79f0\u4e3a\u94fe\u63a5\uff0c\u7531\u53e6\u4e00\u4e2a\u540d\u4e3a<\/span><i><span style=\"font-weight: 400;\">linker<\/span><\/i><span style=\"font-weight: 400;\">\uff08\u94fe\u63a5\u5668\uff0c\u663e\u800c\u6613\u89c1\uff09\u7684\u7a0b\u5e8f\u5b8c\u6210\u3002\u94fe\u63a5\u5668\u83b7\u53d6\u76ee\u6807\u6587\u4ef6\u5e76\u6dfb\u52a0\u7f3a\u5c11\u7684\u5185\u5bb9\u2014\u2014\u4e3b\u8981\u662f\u6765\u81ea\u5176\u4ed6\u76ee\u6807\u6587\u4ef6\u7684\u7b26\u53f7\uff0c\u4ee5\u751f\u4ea7\u53ef\u6267\u884c\u6587\u4ef6\u3002\u5728\u6b64\u4e4b\u540e\uff0c\u7a0b\u5e8f\u5b8c\u5168\u8f6c\u6362\u4e3a\u673a\u5668\u4ee3\u7801\uff0c\u5e76\u53ef\u4ee5\u4e0a\u4f20\u5230\u7535\u8def\u677f\u3002<\/span><\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5828 aligncenter\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image002.jpg\" alt=\"arduino preprocessor\" width=\"234\" height=\"701\" srcset=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image002.jpg 234w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image002-100x300.jpg 100w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image002-49x146.jpg 49w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image002-17x50.jpg 17w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image002-25x75.jpg 25w\" sizes=\"auto, (max-width: 234px) 100vw, 234px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">\u73b0\u5728\uff0c\u6211\u4eec\u5bf9Arduino\u7a0b\u5e8f\u7f16\u8bd1\u6709\u4e86\u4e00\u4e2a\u57fa\u672c\u7684\u4e86\u89e3\u3002\u4f46\u662f\u5728\u4e0a\u8ff0\u6240\u6709\u7f16\u8bd1\u9636\u6bb5\u4e2d\uff0c\u6211\u4eec\u5c06\u53ea\u5173\u6ce8\u7b2c\u4e8c\u4e2a\u9636\u6bb5\uff1a\u9884\u5904\u7406\u5668\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2><b>\u9884\u5904\u7406\u5668\u57fa\u672c\u77e5\u8bc6<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">\u5728\u4e0a\u672c\u4e2d\uff0c\u6211\u63d0\u5230\u9884\u5904\u7406\u5668\u672c\u8d28\u4e0a\u975e\u5e38\u7b80\u5355\uff1a\u63a5\u6536\u6587\u672c\u8f93\u5165\uff0c\u641c\u7d22\u5173\u952e\u5b57\uff0c\u6839\u636e\u627e\u5230\u7684\u5185\u5bb9\u8fdb\u884c\u4e00\u4e9b\u64cd\u4f5c\uff0c\u7136\u540e\u8f93\u51fa\u4e0d\u540c\u7684\u6587\u672c\u3002\u5b83\u975e\u5e38\u7b80\u5355\uff0c\u540c\u65f6\u4e5f\u975e\u5e38\u5f3a\u5927\uff0c\u56e0\u4e3a\u5b83\u5141\u8bb8\u4f60\u7528\u666e\u901aC\/C++\u8bed\u8a00\u5b8c\u6210\u4e00\u4e9b\u672c\u6765\u4f1a\u975e\u5e38\u590d\u6742\u7684\u4e8b\u60c5\uff08\u5982\u679c\u53ef\u80fd\uff09\u3002<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u9884\u5904\u7406\u5668\u4f1a\u641c\u7d22\u4ee5\u4e95\u53f7\uff08#\uff09\u5f00\u5934\u4e14\u540e\u9762\u6709\u6587\u672c\u7684\u884c\u3002\u8fd9\u79cd\u8bed\u53e5\u53eb\u505a<\/span><b><span style=\"font-weight: 400;\">\u9884\u5904\u7406\u5668\u6307\u4ee4<\/span><\/b><span style=\"font-weight: 400;\">\uff0c\u662f\u9884\u5904\u7406\u5668\u7684\u4e00\u79cd\u201c\u547d\u4ee4\u201d\u3002\u9884\u5904\u7406\u5668\u6307\u4ee4\u7684\u5b8c\u6574\u5217\u8868\u4ee5\u53ca\u8be6\u7ec6\u6587\u6863\u7684\u5730\u5740\u5982\u4e0b\u6240\u793a\uff1a<\/span><\/p>\n<p><a href=\"https:\/\/gcc.gnu.org\/onlinedocs\/cpp\/Index-of-Directives.html#Index-of-Directives\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"font-weight: 400;\">https:\/\/gcc.gnu.org\/onlinedocs\/cpp\/Index-of-Directives.html#Index-of-Directives<\/span><\/a><span style=\"font-weight: 400;\">\u3002<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u4e3b\u8981\u5173\u6ce8<\/span><i><span style=\"font-weight: 400;\">#include<\/span><\/i><span style=\"font-weight: 400;\">\u3001<\/span><i><span style=\"font-weight: 400;\">#define<\/span><\/i><span style=\"font-weight: 400;\">\u548c\u6761\u4ef6\u6307\u4ee4\uff0c\u56e0\u4e3a\u8fd9\u662fArduino\u6700\u6709\u7528\u7684\u6307\u4ee4\u3002\u5982\u679c\u60a8\u60f3\u4e86\u89e3\u4e00\u4e9b\u66f4\u201c\u5947\u5f02\u201d\u7684\u6307\u4ee4\uff0c\u6bd4\u5982<\/span><i><span style=\"font-weight: 400;\">#assert<\/span><\/i><span style=\"font-weight: 400;\"> \u6216 <\/span><i><span style=\"font-weight: 400;\">#pragma<\/span><\/i><span style=\"font-weight: 400;\">, \u8bf7\u53c2\u9605\u4e0a\u8ff0\u5730\u5740\uff0c\u4ee5\u83b7\u53d6\u5b98\u65b9\u4fe1\u606f\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2><b>\u6dfb\u52a0\u989d\u5916\u4ee3\u7801\uff1a<i>#include<\/i> \u6307\u4ee4<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">\u8fd9\u53ef\u80fd\u662f\u6700\u8457\u540d\u7684\u9884\u5904\u7406\u5668\u6307\u4ee4\uff0c\u4e0d\u4ec5Arduino\u7231\u597d\u8005\u90fd\u77e5\u9053\uff0c\u800c\u4e14C\/C++\u7f16\u7a0b\u4eba\u5458\u4e5f\u90fd\u4e86\u89e3\u3002\u539f\u56e0\u5f88\u7b80\u5355\uff1a\u8be5\u6307\u4ee4\u7684\u4f5c\u7528\u662f\u5305\u542b\u5e93\u3002\u4f46\u662f\uff0c\u8fd9\u7a76\u7adf\u662f\u5982\u4f55\u5b9e\u73b0\u7684\u5462\uff1f\u786e\u5207\u7684\u8bed\u6cd5\u5982\u4e0b\u6240\u793a\uff1a<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>#include &lt;file&gt;\r\n<\/code><\/pre>\n<\/div>\n<p>\u6216<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>#include \"file\"\r\n<\/code><\/pre>\n<\/div>\n<p><span style=\"font-weight: 400;\">\u4e24\u8005\u7684\u533a\u522b\u6bd4\u8f83\u5c0f\uff0c\u4e3b\u8981\u5728\u4e8e\u9884\u5904\u7406\u5668\u641c\u7d22<\/span><i><span style=\"font-weight: 400;\">file<\/span><\/i><span style=\"font-weight: 400;\">\uff08\u6587\u4ef6\uff09\u7684\u786e\u5207\u4f4d\u7f6e\u3002\u5982\u679c\u662f\u7b2c\u4e00\u53e5\uff0c\u9884\u5904\u7406\u5668\u4ec5\u641c\u7d22IDE\u6307\u5b9a\u7684\u76ee\u5f55\u3002\u5982\u679c\u662f\u7b2c\u4e8c\u53e5\uff0c\u9884\u5904\u7406\u5668\u9996\u5148\u67e5\u770b\u5305\u542b\u6e90\u6587\u4ef6\u7684\u6587\u4ef6\u5939\uff0c\u4e14\u4ec5\u5f53\u6ca1\u6709\u5728\u8be5\u76ee\u5f55\u4e0b\u627e\u5230<\/span><i><span style=\"font-weight: 400;\">file\uff08\u6587\u4ef6\uff09 <\/span><\/i><span style=\"font-weight: 400;\">\u65f6, \u5b83\u624d\u4f1a\u641c\u7d22\u7b2c\u4e00\u53e5\u7684\u641c\u7d22\u76ee\u5f55\u3002\u7531\u4e8e\u5305\u542b\u5e93\u7684\u6587\u4ef6\u5939\u662f\u5728Arduino IDE\u4e2d\u6307\u5b9a\u7684\uff0c\u56e0\u6b64\u5728\u5305\u542b\u5e93\u65f6\u4e24\u8005\u4e4b\u95f4\u6ca1\u6709\u91cd\u5927\u533a\u522b\u3002<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u5f53\u9884\u5904\u7406\u5668\u627e\u5230\u6587\u4ef6\u65f6\uff0c\u5b83\u53ea\u662f\u5c06\u5176\u5185\u5bb9\u590d\u5236\u7c98\u8d34\u5230\u6e90\u4ee3\u7801\u4e2d\uff0c\u4ee5\u66ff\u4ee3\u7a0b\u5e8f\u4e2d\u7684#include\u6307\u4ee4\u3002\u4f46\u662f\uff0c\u5982\u679c\u5728\u4efb\u4f55\u76ee\u5f55\u4e2d\u90fd\u627e\u4e0d\u5230\u6b64\u6587\u4ef6\uff0c\u5c31\u4f1a\u5f15\u53d1\u81f4\u547d\u9519\u8bef\uff0c\u7f16\u8bd1\u505c\u6b62\u3002<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u8981\u8bb0\u4f4f\uff0c\u9884\u5904\u7406\u5668\u53ea\u5904\u7406\u6587\u672c\u2014\u2014\u65e0\u6cd5\u7406\u89e3\u90a3\u4e9b\u7279\u6b8a\u5b57\u6bcd\u548c\u6570\u5b57\u7684\u542b\u4e49\u3002\u6700\u91cd\u8981\u7684\u662f\uff0c\u5b83\u5bf9\u6240\u5305\u542b\u7684\u5185\u5bb9\u548c\u5305\u542b\u6b21\u6570\u7edd\u5bf9\u4e0d\u4f1a\u8fdb\u884c\u66f4\u9ad8\u7ea7\u522b\u7684\u68c0\u67e5\u3002\u8ba9\u6211\u4eec\u6765\u770b\u4e00\u4e0b\u4f7f\u7528\u7f16\u5199\u4e0d\u6b63\u786e\u7684\u5e93\u4f1a\u53d1\u751f\u4ec0\u4e48\u3002<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>#include &lt;ExampleLibrary.h&gt;\r\n\r\nvoid setup() {\r\n\r\n}\r\n\r\n#include &lt;ExampleLibrary.h&gt;\r\n\r\nvoid loop() {\r\n\r\n}\r\n<\/code><\/pre>\n<\/div>\n<p><span style=\"font-weight: 400;\">\u8fd9\u4e2aArduino\u7a0b\u5e8f\u4e2d\u6ca1\u6709\u591a\u5c11\u5185\u5bb9\u3002\u8bf7\u6ce8\u610f\u6211\u4eec\u5305\u542b\u4e86\u4e00\u4e2a\u540d\u4e3a\u201c<\/span><b>ExampleLibrary.h<\/b><span style=\"font-weight: 400;\">\u201d\u7684\u6587\u4ef6\uff0c\u800c\u4e14\u6211\u4eec\u5305\u542b\u4e86\u4e24\u6b21\u3002<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>\/\/This is an example library\r\n\r\nint a = 0;\r\n\r\n\/\/End of example library\r\n<\/code><\/pre>\n<\/div>\n<p><span style=\"font-weight: 400;\">\u201cExampleLibrary.h\u201d\u7684\u5185\u5bb9\u5982\u4e0b\u6240\u793a\u3002\u540c\u6837\uff0c\u9664\u4e86\u4e00\u4e2a\u6574\u6570\u53d8\u91cf\u4e4b\u5916\uff0c\u6ca1\u6709\u591a\u5c11\u5185\u5bb9\u3002\u90a3\u4e48\u5f53\u6211\u4eec\u7f16\u8bd1\u8fd9\u4e2aArduino\u7a0b\u5e8f\u65f6\u4f1a\u53d1\u751f\u4ec0\u4e48\u5462\uff1f<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5829\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image005-copy.jpg\" alt=\"arduino preprocessor\" width=\"700\" height=\"608\" srcset=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image005-copy.jpg 700w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image005-copy-300x261.jpg 300w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image005-copy-168x146.jpg 168w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image005-copy-50x43.jpg 50w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image005-copy-86x75.jpg 86w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">\u9519\u8bef\u4fe1\u606f\u663e\u793a\u53d8\u91cf<\/span><i><span style=\"font-weight: 400;\">a<\/span><\/i><span style=\"font-weight: 400;\">\u58f0\u660e\u4e86\u4e24\u6b21\uff0c\u8fd9\u5bfc\u81f4\u7f16\u8bd1\u5931\u8d25\u3002\u8fd9\u662f\u9884\u5904\u7406\u5668\u5b8c\u6210\u540e\u6e90\u4ee3\u7801\u7684\u6837\u5b50\u3002<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>\/\/This is an example  library\r\n\r\nint a = 0;\r\n\r\n\/\/End of example library\r\n\r\nvoid setup() {\r\n\r\n}\r\n\r\n\/\/This is an example  library\r\n\r\nint a = 0;\r\n\r\n\/\/End of example library\r\n\r\nvoid loop() {\r\n\r\n}\r\n<\/code><\/pre>\n<\/div>\n<p><span style=\"font-weight: 400;\">\u663e\u800c\u6613\u89c1\uff0c\u4e0d\u5e94\u8be5\u591a\u6b21\u5305\u542b\u5e93\uff0c\u4f46\u662f\u5982\u4f55\u5728\u4e0d\u4f9d\u8d56\u7528\u6237\u7684\u60c5\u51b5\u4e0b\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\uff1f\u6807\u51c6\u89e3\u51b3\u65b9\u6848\u662f\u5c06\u6574\u4e2a\u5e93\u5305\u542b\u5728\u4ee5\u4e0b\u7ed3\u6784\u4e2d\uff1a<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>#ifndef _EXAMPLE_LIBRARY_H\r\n#define _EXAMPLE_LIBRARY_H\r\n\r\n\/\/This is an example  library\r\n\r\nint a = 0;\r\n\r\n\/\/End of example library\r\n\r\n#endif\r\n<\/code><\/pre>\n<\/div>\n<p><span style=\"font-weight: 400;\">\u73b0\u5728\uff0c\u7b2c\u4e00\u6b21\u5305\u542b\u5e93\u65f6\uff0c\u9884\u5904\u7406\u5668\u4f1a\u68c0\u67e5\u662f\u5426\u5b58\u5728\u7528\u201c<\/span><i><span style=\"font-weight: 400;\">_EXAMPLE_LIBRARY_H<\/span><\/i><span style=\"font-weight: 400;\">\u201d\u5b9a\u4e49\u7684\u5185\u5bb9\u3002\u7531\u4e8e\u6ca1\u6709\u7c7b\u4f3c\u7684\u4e1c\u897f\u5b58\u5728\uff0c\u9884\u5904\u7406\u5668\u7ee7\u7eed\u4e0b\u4e00\u884c\u5e76\u5b9a\u4e49\u4e00\u4e2a\u540d\u4e3a\u201c<\/span><i><span style=\"font-weight: 400;\">_EXAMPLE_LIBRARY_H<\/span><\/i><span style=\"font-weight: 400;\">\u201d\u7684\u5e38\u91cf\u3002\u7136\u540e\uff0c\u5e93\u4ee3\u7801\u88ab\u590d\u5236\u5230\u7a0b\u5e8f\u4e2d\u3002<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u5f53\u7b2c\u4e8c\u6b21\u5305\u542b\u5e93\u65f6\uff0c\u9884\u5904\u7406\u5668\u4f1a\u518d\u6b21\u68c0\u67e5\u662f\u5426\u5b58\u5728\u540d\u4e3a\u201c<\/span><i><span style=\"font-weight: 400;\">_EXAMPLE_LIBRARY_H<\/span><\/i><span style=\"font-weight: 400;\">\u201d\u7684\u5e38\u91cf\u3002\u8fd9\u6b21\uff0c\u7531\u4e8e\u4e0a\u4e00\u4e2a<\/span><i><span style=\"font-weight: 400;\">#include<\/span><\/i><span style=\"font-weight: 400;\">\u547d\u4ee4\u5df2\u7ecf\u5b9a\u4e49\u4e86\u8be5\u5e38\u91cf\uff0c\u6240\u4ee5\u9884\u5904\u7406\u5668\u4e0d\u4f1a\u5411\u7a0b\u5e8f\u4e2d\u6dfb\u52a0\u4efb\u4f55\u5185\u5bb9\u3002\u4e8e\u662f\uff0c\u7f16\u8bd1\u6210\u529f\u5b8c\u6210\u3002<\/span><i><span style=\"font-weight: 400;\">#ifdef<\/span><\/i><span style=\"font-weight: 400;\"> \u548c <\/span><i><span style=\"font-weight: 400;\">#endif<\/span><\/i><span style=\"font-weight: 400;\">\u662f\u6761\u4ef6\u6307\u4ee4\uff0c\u6211\u4eec\u7a0d\u540e\u5c06\u5bf9\u6b64\u8fdb\u884c\u8ba8\u8bba\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2><b>\u5b9a\u4e49\u4e8b\u7269\uff1a<i>#define<\/i> \u6307\u4ee4<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">\u5728\u4e0a\u4e00\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u7528<\/span><i><span style=\"font-weight: 400;\">#define<\/span><\/i><span style=\"font-weight: 400;\">\u6307\u4ee4\u521b\u5efa\u4e86\u4e00\u4e2a\u5e38\u91cf\uff0c\u4ee5\u51b3\u5b9a\u662f\u5426\u5305\u542b\u4e00\u4e2a\u5e93\u3002\u5728\u5b98\u65b9\u6587\u6863\u4e2d\uff0c\u4efb\u4f55\u7531<\/span><i><span style=\"font-weight: 400;\">#define<\/span><\/i><span style=\"font-weight: 400;\">\u6307\u4ee4\u5b9a\u4e49\u7684\u4e1c\u897f\u90fd\u88ab\u79f0\u4e3a<\/span><i><span style=\"font-weight: 400;\">macro<\/span><\/i><span style=\"font-weight: 400;\">\uff08\u5b8f\uff09, \u56e0\u6b64\u672c\u6587\u4e2d\u6211\u4f1a\u4e00\u76f4\u6cbf\u7528\u8fd9\u4e2a\u672f\u8bed\u3002\u8be5\u6307\u4ee4\u7684\u8bed\u6cd5\u5982\u4e0b\uff1a<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>#define macro_name macro_body\r\n<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u5927\u591a\u6570Arduino\u521d\u5b66\u8005\u53ef\u80fd\u4f1a\u5bf9\u5b8f\u611f\u5230\u56f0\u60d1\u3002\u5982\u679c\u6211\u5b9a\u4e49\u4e00\u4e2a\u5b8f\uff1a<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>#define X 10\r\n<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u90a3\u4e48\u8fd9\u4e0e\u4ee5\u4e0b\u53d8\u91cf\u58f0\u660e\u6709\u4ec0\u4e48\u533a\u522b\u5462\uff1f<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>int Y = 10;\r\n<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u540c\u6837\uff0c\u8fd9\u4e00\u5207\u90fd\u5f52\u7ed3\u4e3a\u9884\u5904\u7406\u5668\u4ec5\u5904\u7406\u6587\u672c\u3002\u9047\u5230<\/span><i><span style=\"font-weight: 400;\">#define<\/span><\/i><span style=\"font-weight: 400;\">\u6307\u4ee4\u65f6\uff0c\u9884\u5904\u7406\u5668\u4f1a\u641c\u7d22\u5176\u4f59\u7684\u6e90\u4ee3\u7801\u5e76\u5c06\u6240\u6709\u51fa\u73b0\u7684\u201cX\u201d\u66ff\u6362\u4e3a\u201c10\u201d\u3002\u8fd9\u610f\u5473\u7740\u4e0e\u53d8\u91cf\u4e0d\u540c\uff0c\u5b8f\u7684\u503c\u6c38\u8fdc\u4e0d\u4f1a\u6539\u53d8\u3002\u6b64\u5916\uff0c\u60a8\u5fc5\u987b\u7262\u8bb0<\/span><b>\u9884\u5904\u7406\u5668\u53ea\u641c\u7d22\u4ee5<i>#define<\/i>\u5f00\u5934\u7684\u6e90\u4ee3\u7801<\/b><span style=\"font-weight: 400;\">\u3002\u8ba9\u6211\u4eec\u770b\u4e00\u4e0b\u4f7f\u7528\u5c1a\u672a\u5b9a\u4e49\u7684\u5b8f\u4f1a\u53d1\u751f\u4ec0\u4e48\u60c5\u51b5\u3002<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>int Y = X;\r\n#define X 10\r\nint Z = X;\r\n\r\nvoid setup() {\r\n \r\n}\r\n\r\nvoid loop() {\r\n \r\n}\r\n<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u7f16\u8bd1\u4e0a\u8ff0\u4ee3\u7801\u4f1a\u53d1\u751f\u4ee5\u4e0b\u9519\u8bef\uff1a<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5830\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image007-copy.jpg\" alt=\"arduino preprocessor\" width=\"700\" height=\"608\" srcset=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image007-copy.jpg 700w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image007-copy-300x261.jpg 300w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image007-copy-168x146.jpg 168w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image007-copy-50x43.jpg 50w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/06\/image007-copy-86x75.jpg 86w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">\u9884\u5904\u7406\u540e\u7684\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>int Y = X;\r\nint Z = 10;\r\n\r\nvoid setup() {\r\n\r\n}\r\n\r\nvoid loop() {\r\n \r\n}\r\n<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u7b2c\u4e00\u884c\u5305\u542b<\/span><i><span style=\"font-weight: 400;\">X<\/span><\/i><span style=\"font-weight: 400;\">\uff0c\u5b83\u88ab\u770b\u4f5c\u4e00\u4e2a\u53d8\u91cf\u3002\u4f46\u662f\uff0c\u8be5\u53d8\u91cf\u4ece\u672a\u58f0\u660e\uff0c\u56e0\u6b64\u7f16\u8bd1\u505c\u6b62\u3002<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u5c3d\u7ba1<\/span><i><span style=\"font-weight: 400;\">#define<\/span><\/i><span style=\"font-weight: 400;\">\u6307\u4ee4\u6700\u5e38\u89c1\u7684\u7528\u9014\u662f\u521b\u5efa\u5e26\u540d\u79f0\u7684\u5e38\u91cf\uff0c\u4f46\u662f\u5b83\u53ef\u4ee5\u505a\u7684\u8fdc\u4e0d\u6b62\u8fd9\u4e9b\u3002\u4f8b\u5982\uff0c\u5047\u8bbe\u60a8\u60f3\u77e5\u9053\u4e24\u4e2a\u7ed9\u5b9a\u6570\u5b57\u4e2d\u54ea\u4e00\u4e2a\u8f83\u5c0f\u3002\u60a8\u53ef\u4ee5\u7f16\u5199\u4e00\u4e2a\u5b9e\u73b0\u6b64\u529f\u80fd\u7684\u51fd\u6570\u3002<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>int min(int a, int b) {\r\n if(a < b) {\r\n   return(a);\r\n }\r\n return(b);\r\n}\r\n<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>\u6216\u8005\u4f7f\u7528\u66f4\u7b80\u5355\u7684\u4e09\u5143\u8fd0\u7b97\u7b26\uff1a<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>int min(int a, int b) {\r\n return((a < b) ? a : b);\r\n}\r\n<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>\u4f46\u662f\uff0c\u8fd9\u4e24\u4e2a\u51fd\u6570\u90fd\u5c06\u88ab\u7f16\u8bd1\u5e76\u5360\u7528\u5b9d\u8d35\u7684\u7a0b\u5e8f\u5b58\u50a8\u7a7a\u95f4\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u7c7b\u4f3c\u51fd\u6570\u7684\u5b8f\u6765\u5b9e\u73b0\u76f8\u540c\u6548\u679c\uff0c\u4f46\u662f\u5360\u7528\u7684\u7a0b\u5e8f\u7a7a\u95f4\u5374\u4f1a\u53d8\u5c11\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>#ifndef MIN\r\n #define MIN(A, B)     (((A) < (B)) ? (A) : (B))\r\n#endif\r\n<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u73b0\u5728\uff0c\u6bcf\u4e2a\u201cMIN(A, B)\u201d\u90fd\u4f1a\u88ab\u66ff\u6362\u4e3a\u201c(((A) < (B)) ? (A) : (B))\u201d\uff0c\u5176\u201cA\u201d\u548c\u201cB\u201d\u53ef\u4ee5\u662f\u6570\u5b57\uff0c\u4e5f\u53ef\u4ee5\u662f\u53d8\u91cf\u3002\u8bf7\u6ce8\u610f\uff0c<\/span><i><span style=\"font-weight: 400;\">#define<\/span><\/i><span style=\"font-weight: 400;\">\u5305\u542b\u5728\u76f8\u540c\u7684\u4fdd\u62a4\u6027\u7ed3\u6784\u4e2d\uff0c\u4ee5\u9632\u6b62\u7528\u6237\u91cd\u590d\u5b9a\u4e49\u5b8f\u3002<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u521b\u5efa\u5b8f\u65f6\uff0c\u60a8\u5fc5\u987b\u8bb0\u4f4f\uff0c\u7cfb\u7edf\u5c06\u5b8f\u4f5c\u4e3a\u6587\u672c\u8fdb\u884c\u5904\u7406\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u5728\u4e0a\u9762\u7684\u5b9a\u4e49\u4e2d\uff0c\u51e0\u4e4e\u6240\u6709\u5185\u5bb9\u90fd\u5305\u542b\u5728\u62ec\u53f7\u4e2d\u3002\u8bf7\u731c\u6d4b\u4ee5\u4e0b\u8fd0\u7b97\u7684\u7ed3\u679c\u3002<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>#ifndef MULTIPLY\r\n #define MULTIPLY(A, B)     A * B\r\n#endif\r\n\r\n\/\/some code...\r\n\r\nint result = MULTIPLY(2 - 0, 3);\r\n<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><i><span style=\"font-weight: 400;\">\u7ed3\u679c<\/span><\/i><span style=\"font-weight: 400;\">\u5e94\u8be5\u662f6\uff0c\u56e0\u4e3a2\u20130=2\uff0c\u7136\u540e2x3=6\uff0c\u5bf9\u5427\uff1f\u5982\u679c\u6211\u544a\u8bc9\u4f60\u7ed3\u679c\u662f2\u5462\uff1f\u5b9e\u9645\u7f16\u8bd1\u7684\u5185\u5bb9\u5982\u4e0b\uff1a<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>int result = 2 - 0 * 3;\r\n<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u7531\u4e8e\u4e58\u6cd5\u4f18\u5148\u4e8e\u51cf\u6cd5\uff0c\u56e0\u6b64\u5f88\u660e\u663e\u7ed3\u679c\u80af\u5b9a\u662f2\uff0c\u56e0\u4e3a3x0=0\uff0c\u7136\u540e2-0=2\u3002\u6b63\u786e\u7684\u7248\u672c\u5982\u4e0b\u6240\u793a\uff1a<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>#ifndef MULTIPLY\r\n #define MULTIPLY(A, B)     ((A) * (B))\r\n#endif\r\n<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2><b>\u6761\u4ef6\u7f16\u8bd1\uff1a<i>#if<\/i>\u6307\u4ee4<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">\u5728\u524d\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4f7f\u7528\u4e86<\/span><i><span style=\"font-weight: 400;\">#ifndef<\/span><\/i><span style=\"font-weight: 400;\">\u6307\u4ee4\uff0c\u4e8e\u662f\u6211\u53ef\u4ee5\u68c0\u67e5\u662f\u5426\u5df2\u7ecf\u5305\u542b\u4e86\u5e93\u3002\u8be5\u6307\u4ee4\u53ef\u7528\u4e8e\u5b9e\u73b0\u4ec5\u7528C\/C++\u8bed\u8a00\u4e0d\u53ef\u80fd\u5b9e\u73b0\u7684\u5185\u5bb9\uff1a\u6761\u4ef6\u8bed\u53e5\u3002\u8fd9\u4e9b\u6307\u4ee4\u7684\u8bed\u6cd5\u5982\u4e0b\u6240\u793a\uff1a<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>#if expression\r\n\r\n  \/\/compile this code\r\n\r\n#elif different_expression\r\n \r\n \/\/compile this different code\r\n\r\n#else\r\n \r\n \/\/compile this entirely different code\r\n\r\n#endif\r\n<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u6761\u4ef6\u8bed\u53e5\u7684\u5e38\u7528\u529f\u80fd\u662f\u68c0\u67e5\u4e00\u4e2a\u5b8f\u662f\u5426\u5df2\u5b9a\u4e49\u3002\u4e3a\u6b64\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u51e0\u4e2a\u4e13\u95e8\u7684\u6307\u4ee4\uff1a<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>#ifndef macro_name\r\n\r\n  \/\/compile this code if macro_name does not exist\r\n\r\n#endif\r\n<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u6211\u4eec\u5df2\u7ecf\u719f\u6089\u4e86\u4e0a\u8ff0\u5185\u5bb9\uff0c\u56e0\u4e3a\u6211\u4eec\u4e4b\u524d\u4f7f\u7528\u6b64\u6307\u4ee4\u6765\u68c0\u67e5\u662f\u5426\u5df2\u5305\u542b\u5e93\u3002\u60a8\u4e5f\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u6761\u4ef6\uff1a<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>#ifdef macro_name\r\n\r\n  \/\/compile this code if macro_name exists\r\n\r\n#endif\r\n<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u4ee5\u4e0a\u8bed\u53e5\u53ea\u662f<\/span><b><i>#if defined<\/i><\/b><span style=\"font-weight: 400;\">\u7684\u7b80\u5199\uff0c\u53ef\u6839\u636e\u5355\u4e2a\u6761\u4ef6\u6d4b\u8bd5\u591a\u4e2a\u5b8f\u3002\u8bf7\u6ce8\u610f\uff0c\u6bcf\u4e2a\u6761\u4ef6\u90fd\u5fc5\u987b\u7528<\/span><b><i>#endif <\/i><\/b><span style=\"font-weight: 400;\">\u6307\u4ee4\u7ed3\u675f\uff0c\u4ece\u800c\u6307\u5b9a\u4ee3\u7801\u7684\u54ea\u4e9b\u90e8\u5206\u53d7\u6761\u4ef6\u5f71\u54cd\uff0c\u54ea\u4e9b\u90e8\u5206\u4e0d\u53d7\u6761\u4ef6\u5f71\u54cd\u3002<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u5b9e\u9645\u7684\u4f8b\u5b50\u3002\u5047\u8bbe\u60a8\u7f16\u5199\u4e86\u4e00\u4e2a\u5e93\uff0c\u5e76\u4e14\u5e0c\u671b\u5b83\u5728Arduino UNO\u548cArduino Mega\u4e0a\u90fd\u80fd\u6b63\u5e38\u5de5\u4f5c\u3002\u8fd9\u4e3b\u610f\u4e0d\u9519\uff0c\u5bf9\u5427\uff1f\u4fbf\u643a\u4ee3\u7801\u603b\u6bd4\u4e3a\u53e6\u4e00\u5757\u7535\u8def\u677f\u4fee\u6539\u5e93\u66f4\u5bb9\u6613\u3002\u4f46\u662f\uff0c\u5982\u679c\u60a8\u7684\u5e93\u4f7f\u7528\u4e86SPI\u603b\u7ebf\u5462\uff1f\u8be5\u603b\u7ebf\u5728Arduino UNO\u4e0a\u7528\u7684\u662f11-13\u5f15\u811a\uff0c\u4f46\u662f\u5728Mega\u4e0a\u5374\u662f50-52\u5f15\u811a\u3002<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u90a3\u4e48\u60a8\u5982\u4f55\u544a\u8bc9\u7f16\u8bd1\u5668\u6839\u636e\u4e0d\u540c\u5f00\u53d1\u677f\u4f7f\u7528\u76f8\u5e94\u7684\u5f15\u811a\u5462\uff1f\u60a8\u731c\u5bf9\u4e86\u2014\u2014\u6761\u4ef6\u8bed\u6cd5\uff01\u6839\u636e\u60a8\u5728Arduino IDE\u4e2d\u9009\u62e9\uff08\u201cTools\u201d &gt; \u201cBoard\u201d\u83dc\u5355\uff09\u7684\u5f00\u53d1\u677f\uff0cIDE\u5c06\u5b9a\u4e49\u4e0d\u540c\u7684\u5b8f\uff0c\u4ece\u800c\u4ec5\u7f16\u8bd1\u4e0e\u6240\u9009\u5f00\u53d1\u677f\u76f8\u5173\u7684\u4ee3\u7801\u90e8\u5206\uff01\u8fd9\u975e\u5e38\u5f3a\u5927\uff0c\u56e0\u4e3a\u60a8\u53ef\u4ee5\u5b9e\u73b0\u4ee5\u4e0b\u529f\u80fd\uff1a<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)\r\n \r\n \/\/this will compile for Arduino UNO, Pro and older boards\r\n int _sck = 13;\r\n int _miso = 12;\r\n int _mosi = 11;\r\n\r\n#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)\r\n \r\n \/\/this will compile for Arduino Mega\r\n int _sck = 52;\r\n int _miso = 50;\r\n int _mosi = 51;\r\n\r\n#endif\r\n<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u600e\u4e48\u6837\uff0c\u6f02\u4eae\u5427\uff1f\u4ec5\u7528\u4e09\u884c\u4ee3\u7801\uff0c\u6211\u4eec\u5c31\u5236\u4f5c\u4e86\u4e00\u4e2a\u591a\u5e73\u53f0\u4fbf\u643a\u5e93\uff01\u53e6\u5916\uff0c\u8fd9\u6b63\u662fRohmMultiSensor\u5e93\uff08<\/span><a href=\"https:\/\/techclass.wfjydl.com\/knowledge\/deviceplus\/how-tos\/arduino\/lightweight-arduino-library-for-rohm-sensor-evaluation-kit\" target=\"_blank\" rel=\"noopener noreferrer\"><b>\u9002\u7528\u4e8e极悦娱乐\u4f20\u611f\u5668\u8bc4\u4f30\u5957\u4ef6\u7684\u8f7b\u91cf\u7ea7Arduino\u5e93<\/b><\/a><span style=\"font-weight: 400;\">\uff09\u5982\u4f55\u77e5\u9053\u5e94\u8be5\u4e3a\u6240\u9009\u4f20\u611f\u5668\u7f16\u8bd1\u54ea\u4e9b\u4ee3\u7801\u3002\u5982\u679c\u60a8\u770b\u4e00\u4e0b\u5934\u6587\u4ef6<\/span><i><span style=\"font-weight: 400;\">RohmMultiSensor.h<\/span><\/i><span style=\"font-weight: 400;\">\u91cc\u9762\u7684\u5185\u5bb9\uff0c\u60a8\u53ea\u4f1a\u770b\u5230\u51e0\u4e2a<\/span><i><span style=\"font-weight: 400;\">#ifdef<\/span><\/i><span style=\"font-weight: 400;\">\u548c\u51e0\u4e2a<\/span><i><span style=\"font-weight: 400;\">#include<\/span><\/i><span style=\"font-weight: 400;\">\u6307\u4ee4\u3002\u7531\u4e8e\u6240\u6709\u7279\u5b9a\u4f20\u611f\u5668\u4ee3\u7801\u90fd\u5b58\u50a8\u5728\u5355\u72ec\u7684<\/span><i><span style=\"font-weight: 400;\">.cpp<\/span><\/i><span style=\"font-weight: 400;\">\u6587\u4ef6\u4e2d\uff0c\u56e0\u6b64\u5c06\u65b0\u4f20\u611f\u5668\u6dfb\u52a0\u5230\u5e93\u4e2d\u5f88\u5bb9\u6613\u2014\u2014\u53ea\u9700\u521b\u5efa\u53e6\u4e00\u4e2a\u6587\u4ef6\uff0c\u7136\u540e\u521b\u5efa\u4e0e\u5176\u4ed6\u4f20\u611f\u5668\u76f8\u540c\u7684<\/span><i><span style=\"font-weight: 400;\">#ifdef &#8211; #include &#8211; #endif<\/span><\/i><span style=\"font-weight: 400;\">\u7ed3\u6784\u5373\u53ef\u3002\u5b8c\u6210\uff01<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2><b>\u63d0\u4f9b\u53cd\u9988\uff1a<i>#warning<\/i> \u548c <i>#error<\/i> \u6307\u4ee4<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">\u6211\u4eec\u6700\u540e\u8981\u4ecb\u7ecd\u7684\u6307\u4ee4\u662f<\/span><b><i>#warning<\/i><\/b><span style=\"font-weight: 400;\"> \u548c <\/span><b><i>#error<\/i><\/b><span style=\"font-weight: 400;\">\u3002\u4e24\u8005\u4f46\u662f\u4e0d\u8a00\u81ea\u660e\uff0c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>#warning \"message\"\r\n<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u548c<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>#error \"message\"\r\n<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u9884\u5904\u7406\u5668\u9047\u5230\u8fd9\u4e9b\u6307\u4ee4\u65f6\uff0c\u5b83\u4f1a\u5c06<\/span><i><span style=\"font-weight: 400;\">message<\/span><\/i><span style=\"font-weight: 400;\">\u6253\u5370\u5230Arduino IDE\u63a7\u5236\u53f0\u4e2d\u3002\u4e24\u8005\u4e4b\u95f4\u7684\u533a\u522b\u5728\u4e8e\uff0c\u53d1\u751f<\/span><i><span style=\"font-weight: 400;\">#warning<\/span><\/i><span style=\"font-weight: 400;\">\u4e4b\u540e\uff0c\u7f16\u8bd1\u6b63\u5e38\u8fdb\u884c\uff0c\u800c<\/span><i><span style=\"font-weight: 400;\">#error<\/span><\/i><span style=\"font-weight: 400;\">\u5219\u4f1a\u5b8c\u5168\u505c\u6b62\u7f16\u8bd1\u3002<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u6211\u4eec\u53ef\u4ee5\u5728\u524d\u6587\u7684\u4f8b\u5b50\u4e2d\u4f7f\u7528\u8fd9\u4e24\u4e2a\u8bed\u53e5\uff1a<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)\r\n\r\n  \/\/this will compile for Arduino UNO, Pro and older boards\r\n int _sck = 13;\r\n int _miso = 12;\r\n int _mosi = 11;\r\n \r\n#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)\r\n\r\n \/\/this will compile for Arduino Mega\r\n int _sck = 52;\r\n int _miso = 50;\r\n int _mosi = 51;\r\n \r\n#else\r\n\r\n #error \u201cUnsupported board selected!\u201d\r\n\r\n#endif\r\n<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u8fd9\u6837\uff0c\u5f53\u7528\u6237\u5c1d\u8bd5\u4e3a\u5176\u4ed6Arduino\u5f00\u53d1\u677f\uff08\u6bd4\u5982Y\u00fan\u3001LilyPad\u7b49\uff09\u7f16\u8bd1\u8be5\u5e93\u65f6\uff0c\u7f16\u8bd1\u4f1a\u5931\u8d25\uff0c\u4e0e\u6ca1\u6709\u5b9a\u4e49SPI\u5f15\u811a\u6ca1\u6709\u4efb\u4f55\u5173\u7cfb\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2><b>\u7ed3\u8bba<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u4ecb\u7ecd\u4e86C\/C++\u9884\u5904\u7406\u5668\u7684\u76f8\u5173\u77e5\u8bc6\u3002\u5e0c\u671b\u60a8\u770b\u8fc7\u672c\u6587\u4e4b\u540e\uff0c\u5c31\u4e0d\u4f1a\u518d\u5bb3\u6015<\/span><b>\u7f16\u8bd1<\/b><span style=\"font-weight: 400;\">\u3001<\/span><b>\u9884\u5904\u7406\u5668<\/b><span style=\"font-weight: 400;\">\u3001\u6216<\/span><b>\u6307\u4ee4<\/b><span style=\"font-weight: 400;\">\u7b49\u672f\u8bed\u4e86\u3002\u6211\u603b\u7ed3\u4e00\u4e0b\u672c\u6587\u63cf\u8ff0\u7684\u6700\u91cd\u8981\u7684\u51e0\u70b9\u5185\u5bb9\uff1a<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\">\u7f16\u5199\u5e93\u65f6\uff0c\u8bf7\u52a1\u5fc5\u5c06\u5176\u653e\u5728 <\/span><i><span style=\"font-weight: 400;\">#ifndef &#8211; #define &#8211; #endif<\/span><\/i><span style=\"font-weight: 400;\">\u7ed3\u6784\u4e2d\u3002\u8fd9\u4e2a\u7ed3\u6784\u6211\u4eec\u5df2\u7ecf\u89c1\u8fc7\u591a\u6b21\u4e86\u3002\u8fd9\u53ef\u80fd\u4f1a\u4e3a\u60a8\u7701\u53bb\u4e00\u4e9b\u9ebb\u70e6\u3002\u5b9a\u4e49\u7c7b\u4f3c\u51fd\u6570\u7684\u5b8f\u65f6\u540c\u6837\u5e94\u8be5\u8fd9\u6837\u505a\u3002<\/li>\n<li style=\"font-weight: 400;\">\u7f16\u5199\u4ee3\u7801\u65f6\uff0c\u5e94\u786e\u4fdd\u7a0b\u5e8f\u6613\u4e8e\u79fb\u690d\u5230\u5176\u4ed6Arduino\u677f\u4e0a\u3002\u76f8\u4fe1\u6211\uff0c\u672a\u96e8\u7ef8\u7f2a\u8981\u6bd4\u51fa\u73b0\u4e0d\u517c\u5bb9\u95ee\u9898\u4e4b\u540e\u518d\u60f3\u6cd5\u89e3\u51b3\u8981\u5bb9\u6613\u5f97\u591a\u3002<\/li>\n<li style=\"font-weight: 400;\">\u5206\u800c\u6cbb\u4e4b\uff01\u51e0\u4e2a\u8f83\u5c0f\u7684\u6587\u4ef6\u603b\u6bd4\u4e00\u4e2a1000\u591a\u884c\u7684\u5927\u6587\u4ef6\u8981\u597d\u5f97\u591a\u3002<\/li>\n<\/ol>\n<div class=\"author-box-wrapper\">\n<div class=\"avatar-wrapper\">\n\t\t<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/micro.wfjydl.com\/deviceplus\/wp-content\/uploads\/2019\/03\/Jan-Gromes_avatar_1472220138-64x64.jpg\" width=\"64\" height=\"64\" alt=\"DevicePlus \u7f16\u8f91\u56e2\u961f\">\n\t<\/div>\n<div class=\"desc-wrapper\">\n<h5>Jan Gromes<\/h5>\n<div class=\"desc\">\n<p>Jan\u76ee\u524d\u5728\u5e03\u5c14\u8bfa\u7406\u5de5\u5927\u5b66\u5b66\u4e60\u7535\u6c14\u5de5\u7a0b\u3002\u4ed6\u62e5\u6709\u591a\u5e74\u4f7f\u7528Arduino\u548c\u5176\u4ed6\u5fae\u63a7\u5236\u5668\u6784\u5efa\u9879\u76ee\u7684\u7ecf\u9a8c\u3002\u4ed6\u7684\u7279\u6b8a\u5174\u8da3\u5728\u4e8e\u673a\u5668\u4eba\u7cfb\u7edf\u7684\u673a\u68b0\u8bbe\u8ba1\u3002<\/p>\n<\/div><\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"\u8fd9\u7bc7\u6587\u7ae0\u6765\u6e90\u4e8eDevicePlus.com\u82f1\u8bed\u7f51\u7ad9\u7684\u7ffb\u8bd1\u7a3f\u3002 \u5728\u9002\u7528\u4e8e极悦娱乐\u4f20\u611f\u5668\u8bc4\u4f30\u5957\u4ef6\u7684\u8f7b\u91cf\u7ea7Arduino\u5e93\u4e2d\uff0c\u6211\u4ecb\u7ecd\u4e86RohmMultiSensor\u2014\u2014\u5e2e\u60a8\u8f7b\u677e\u8fde\u63a5极悦娱乐\u4f20\u611f\u5668\u8bc4\u4f30\u5957\u4ef6\u591a\u4e2a\u4f20\u611f\u5668\u7684Arduin [&hellip;]","protected":false},"author":3,"featured_media":20706,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1130],"tags":[],"class_list":["post-6924","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino"],"acf":[],"wps_subtitle":"","_links":{"self":[{"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/posts\/6924","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/comments?post=6924"}],"version-history":[{"count":11,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/posts\/6924\/revisions"}],"predecessor-version":[{"id":11511,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/posts\/6924\/revisions\/11511"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/media\/20706"}],"wp:attachment":[{"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/media?parent=6924"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/categories?post=6924"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/tags?post=6924"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}