{"id":8417,"date":"2025-12-22T20:16:20","date_gmt":"2025-12-22T11:16:20","guid":{"rendered":"https:\/\/www.chihayafuru.jp\/tech\/?p=8417"},"modified":"2025-12-26T05:13:03","modified_gmt":"2025-12-25T20:13:03","slug":"ir%e3%83%aa%e3%83%a2%e3%82%b3%e3%83%b3%e7%b0%a1%e6%98%93%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/archives\/8417","title":{"rendered":"IR\u30ea\u30e2\u30b3\u30f3\u7c21\u6613\u89e3\u6790"},"content":{"rendered":"<p>M5StickC Plus2 \u3068 Ir Remote Unit \u3092\u7d44\u307f\u5408\u308f\u305b\u3066NEC\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306e\u8d64\u5916\u7dda\u30ea\u30e2\u30b3\u30f3\u4fe1\u53f7\u7c21\u6613\u89e3\u6790\u30b9\u30b1\u30c3\u30c1\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002<\/p>\n<p><!--more--><\/p>\n<h3>\u30b9\u30b1\u30c3\u30c1<\/h3>\n<pre class=\"lang:c decode:true \" >#include &lt;M5StickCPlus2.h&gt;\r\n\r\nconst int IR_RECEIVE_PORT_NO = 33;\r\nconst int NUM_OF_BURST_BITS = 16 * 2;\r\nconst int NUM_OF_FRAME_BITS = 100 * 2;\r\nconst int BIT_PERIOD = 562; \/\/ microseconds\r\n\r\nint received_counter = 0;\r\nint frame_counter = 0;\r\nbool is_started = false;\r\n\r\nvoid setup()\r\n{\r\n    M5.begin();\r\n    M5.Power.begin();\r\n    M5.Display.setRotation(1);\r\n    Serial.begin(115200);\r\n    pinMode(IR_RECEIVE_PORT_NO, INPUT);\r\n    M5.Lcd.setTextSize(2);\r\n    M5.Lcd.setCursor(0, 0);\r\n    M5.Lcd.print(\"Checking IR receiver\");\r\n}\r\n\r\nvoid loop()\r\n{\r\n    const int received_bit = digitalRead(IR_RECEIVE_PORT_NO) ? 0 : 1;\r\n\r\n    if (received_bit != 0) {    \/\/ detected Infrared Signal\r\n        received_counter++;\r\n    } else {                    \/\/ NOT detected Infrared Signal\r\n        received_counter = 0;\r\n    }\r\n\r\n    if (received_counter &gt;= NUM_OF_BURST_BITS) {\r\n        frame_counter = NUM_OF_FRAME_BITS;\r\n    }\r\n\r\n    if (frame_counter &gt;= 0) {\r\n        if (frame_counter == NUM_OF_FRAME_BITS) {\r\n            M5.Lcd.setCursor(0, 25);\r\n            M5.Lcd.print(\"detected!\");\r\n            Serial.print(\"\\n\");\r\n        } else if (frame_counter &gt; 0) {\r\n            if (is_started == true) {\r\n                Serial.print(received_bit);\r\n            } else {\r\n                if (received_bit != 0) {\r\n                    Serial.print(received_bit);\r\n                    is_started = true;\r\n                } else {\r\n                    ;   \/\/ skip space bits\r\n                }\r\n            }\r\n        } else {\r\n            M5.Lcd.setCursor(0, 25);\r\n            M5.Lcd.print(\"         \");\r\n            is_started = false;\r\n        }\r\n\r\n        frame_counter--;\r\n    }\r\n    \r\n    delayMicroseconds(BIT_PERIOD \/ 2);\r\n}<\/pre>\n<h3>\u51fa\u529b\u4f8b<\/h3>\n<pre class=\"lang:default highlight:0 decode:true \" >1100110011001100110011011101100110000001100000111000001100000...001100<\/pre>\n<p>\u8d64\u5916\u7dda2\u6b21\u5909\u8abf(On\/Off)\u5468\u671f 562.5\u30de\u30a4\u30af\u30ed\u79d2 \u306b\u5bfe\u3057\u3066\u7aef\u6570\u3092\u5207\u308a\u6368\u3066\u3066\u3044\u308b\u305f\u3081\u3001\u3068\u3053\u308d\u3069\u3053\u308d\u3067 0 \u3068 1 \u306e\u5468\u671f\u304c\u305a\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u307b\u307c\u4e00\u5b9a\u9593\u9694\u3067 &quot;00&quot; \u3068 &quot;11&quot; \u3092\u7e70\u308a\u8fd4\u3057\u3066\u3044\u308b\u3053\u3068\u304c\u89b3\u5bdf\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>\u30d1\u30eb\u30b9\u8ddd\u96e2\u7b26\u53f7\u5316 (PDM : Pulse-Distance Encoding)<\/h3>\n<p>NEC\u30d7\u30ed\u30c8\u30b3\u30eb\u306e\u3070\u3042\u3044<\/p>\n<table>\n<tbody>\n<tr>\n<th>\u7b26\u53f7\u8ad6\u7406<\/th>\n<th>\u30d1\u30eb\u30b9\u8ddd\u96e2<\/th>\n<th>\u30d1\u30eb\u30b9\u5217\u306e\u4f8b<\/th>\n<\/tr>\n<tr>\n<td>0 (false)<\/td>\n<td>1<\/td>\n<td><code>1100<\/code><\/td>\n<\/tr>\n<tr>\n<td>1 (true)<\/td>\n<td>3<\/td>\n<td><code>11000000<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\u30d1\u30eb\u30b9\u5e45\u3068\u30b9\u30da\u30fc\u30b9\u5e45<\/h4>\n<ul>\n<li>\u30d1\u30eb\u30b9\u5e45 : \u7b26\u53f7\u306b\u95a2\u308f\u3089\u305a\u4e00\u5b9a<\/li>\n<li>\u30b9\u30da\u30fc\u30b9\u5e45 : \u7b26\u53f7\u306b\u3088\u308a\u9577\u77ed<\/li>\n<\/ul>\n<p>\u203b \u30b9\u30da\u30fc\u30b9 : \u30d1\u30eb\u30b9\u3068\u30d1\u30eb\u30b9\u306e\u9593\u306e\u7121\u4fe1\u53f7\u6642\u9593\u3002\u30ae\u30e3\u30c3\u30d7\u3002<\/p>\n<h4>\u30d1\u30eb\u30b9\u8ddd\u96e2<\/h4>\n<p>\u30d1\u30eb\u30b9\u5e45\u3068\u30b9\u30da\u30fc\u30b9\u5e45\u306e\u6bd4\u3002\u30d1\u30eb\u30b9\u8ddd\u96e2\u304c <code>1<\/code> \u306e\u3068\u304d\u30d1\u30eb\u30b9\u5217\u306f &quot;<code>1100<\/code>&quot; \u3084 &quot;<code>111000<\/code>&quot;, &quot;<code>11110000<\/code>&quot; \u3068\u306a\u308b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>M5StickC Plus2 \u3068 Ir Remote Unit \u3092\u7d44\u307f\u5408\u308f\u305b\u3066NEC\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306e\u8d64\u5916\u7dda\u30ea\u30e2\u30b3\u30f3\u4fe1\u53f7\u7c21\u6613\u89e3\u6790\u30b9\u30b1\u30c3\u30c1\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[108],"class_list":["post-8417","post","type-post","status-publish","format-standard","hentry","category-memo","tag-m5stack"],"_links":{"self":[{"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/posts\/8417","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/comments?post=8417"}],"version-history":[{"count":32,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/posts\/8417\/revisions"}],"predecessor-version":[{"id":8450,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/posts\/8417\/revisions\/8450"}],"wp:attachment":[{"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/media?parent=8417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/categories?post=8417"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/tags?post=8417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}