{"id":83118,"date":"2020-08-24T17:16:40","date_gmt":"2020-08-24T11:16:40","guid":{"rendered":"http:\/\/rcl-radio.ru\/?p=83118"},"modified":"2022-01-08T16:48:48","modified_gmt":"2022-01-08T10:48:48","slug":"ky-040-arduino","status":"publish","type":"post","link":"http:\/\/rcl-radio.ru\/?p=83118","title":{"rendered":"KY-040 Arduino"},"content":{"rendered":"<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr>\n<td style=\"width: 50%;\">\n<p style=\"text-align: center;\"><strong>KY-040<\/strong><\/p>\n<p><a href=\"http:\/\/rcl-radio.ru\/wp-content\/uploads\/2020\/08\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-\u043e\u0442-2020-08-24-163629.png\" class=\"highslide-image\" onclick=\"return hs.expand(this);\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-83119\" src=\"http:\/\/rcl-radio.ru\/wp-content\/uploads\/2020\/08\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-\u043e\u0442-2020-08-24-163629.png\" alt=\"\" width=\"186\" height=\"197\" srcset=\"http:\/\/rcl-radio.ru\/wp-content\/uploads\/2020\/08\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-\u043e\u0442-2020-08-24-163629.png 436w, http:\/\/rcl-radio.ru\/wp-content\/uploads\/2020\/08\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-\u043e\u0442-2020-08-24-163629-200x212.png 200w\" sizes=\"auto, (max-width: 186px) 100vw, 186px\" \/><\/a><\/td>\n<td style=\"width: 50%;\"><a href=\"http:\/\/rcl-radio.ru\/wp-content\/uploads\/2020\/08\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-\u043e\u0442-2020-08-24-164156.png\" class=\"highslide-image\" onclick=\"return hs.expand(this);\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83120\" src=\"http:\/\/rcl-radio.ru\/wp-content\/uploads\/2020\/08\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-\u043e\u0442-2020-08-24-164156.png\" alt=\"\" width=\"360\" height=\"295\" srcset=\"http:\/\/rcl-radio.ru\/wp-content\/uploads\/2020\/08\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-\u043e\u0442-2020-08-24-164156.png 360w, http:\/\/rcl-radio.ru\/wp-content\/uploads\/2020\/08\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-\u043e\u0442-2020-08-24-164156-200x164.png 200w\" sizes=\"auto, (max-width: 360px) 100vw, 360px\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u042d\u043d\u043a\u043e\u0434\u0435\u0440\u044b KY-040 \u0447\u0430\u0441\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442 \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 Arduino. KY-040 \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0432 \u0432\u0438\u0434\u0435 \u043c\u043e\u0434\u0443\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u043b\u0430\u0442\u044b \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u044d\u043d\u043a\u043e\u0434\u0435\u0440 \u0438 3 \u043f\u043e\u0434\u0442\u044f\u0433\u0438\u0432\u0430\u044e\u0449\u0438\u0445 (\u043a +5 \u0412) \u0440\u0435\u0437\u0438\u0441\u0442\u043e\u0440\u0430 \u043d\u043e\u043c\u0438\u043d\u0430\u043b\u043e\u043c 10 \u043a\u041e\u043c. \u041f\u0440\u0438 \u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u0440\u0443\u0447\u043a\u0438 \u043c\u043e\u0434\u0443\u043b\u044f \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0432\u0430 \u0441\u0438\u0433\u043d\u0430\u043b\u0430 (A \u0438 B), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u043d\u044b \u043f\u043e \u0444\u0430\u0437\u0435.\u00a0 \u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u0441\u0438\u0433\u043d\u0430\u043b \u0410 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u043e\u0442 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u043a \u043d\u0443\u043b\u044e, \u043c\u044b \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u044b\u0445\u043e\u0434\u0430 \u0412. \u0415\u0441\u043b\u0438 \u0412 \u0432 \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438, \u0437\u043d\u0430\u0447\u0438\u0442 \u044d\u043d\u043a\u043e\u0434\u0435\u0440 \u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0447\u0430\u0441\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0435\u043b\u043a\u0435, \u0435\u0441\u043b\u0438 \u0412 \u043d\u0443\u043b\u044c, \u0442\u043e \u044d\u043d\u043a\u043e\u0434\u0435\u0440 \u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0442\u0438\u0432 \u0447\u0430\u0441\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0435\u043b\u043a\u0438. \u0421\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u043e\u0431\u0430 \u0432\u044b\u0445\u043e\u0434\u0430, \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f, \u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 \u0438\u043c\u043f\u0443\u043b\u044c\u0441\u043e\u0432 \u0441 \u0410 \u0432\u044b\u0445\u043e\u0434\u0430 &#8212; \u0443\u0433\u043e\u043b \u043f\u043e\u0432\u043e\u0440\u043e\u0442\u0430.<\/p>\n<div id=\"marketWidget\"><\/div>\n<p>\u0427\u0442\u043e \u0431\u044b \u0431\u0435\u0437\u043e\u0448\u0438\u0431\u043e\u0447\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0443\u0433\u043e\u043b \u043f\u043e\u0432\u043e\u0440\u043e\u0442\u0430 \u0438 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0433\u043e \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c (\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c) \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432\u044b\u0445\u043e\u0434\u043e\u0432 A \u0438 B\u00a0 (CLK \u0438 DT) \u044d\u043d\u043a\u043e\u0434\u0435\u0440\u0430, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0441\u043a\u0435\u0442\u0447\u0430 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u043f\u0435\u0440\u0438\u043e\u0434 \u043e\u043f\u0440\u043e\u0441\u0430. \u042d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0434\u0432\u0443\u043c\u044f \u043f\u0443\u0442\u044f\u043c\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f \u0438\u043b\u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0442\u0430\u0439\u043c\u0435\u0440\u0430.<\/p>\n<p>\u041d\u0438\u0436\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u0441\u043a\u0435\u0442\u0447 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <strong>Timer2<\/strong>\u00a0 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0433\u043e \u043e\u043f\u0440\u043e\u0441\u0430 \u0432\u044b\u0445\u043e\u0434\u043e\u0432\u00a0 CLK \u0438 DT \u044d\u043d\u043a\u043e\u0434\u0435\u0440\u0430.<\/p>\n<pre><span style=\"color: #5e6d03;\">#define<\/span> <span style=\"color: #000000;\">CLK<\/span> <span style=\"color: #000000;\">8<\/span>\r\n<span style=\"color: #5e6d03;\">#define<\/span> <span style=\"color: #000000;\">DT<\/span> \u00a0<span style=\"color: #000000;\">9<\/span>\r\n\r\n<span style=\"color: #00979c;\">bool<\/span> <span style=\"color: #000000;\">enc_a<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #000000;\">enc_b<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #000000;\">enc_old_a<\/span><span style=\"color: #000000;\">;<\/span>\r\n<span style=\"color: #00979c;\">int<\/span> <span style=\"color: #000000;\">enc_data<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #000000;\">enc_data_old<\/span><span style=\"color: #000000;\">;<\/span>\r\n\r\n<span style=\"color: #00979c;\">void<\/span> <span style=\"color: #5e6d03;\">setup<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">{<\/span>\r\n \u00a0<b><span style=\"color: #d35400;\">Serial<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">begin<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">9600<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span>\r\n \u00a0<span style=\"color: #000000;\">TCCR1B<\/span> <span style=\"color: #434f54;\">|=<\/span> <span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1<\/span> <span style=\"color: #434f54;\">&lt;&lt;<\/span> <span style=\"color: #000000;\">WGM22<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #434f54;\">|<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1<\/span> <span style=\"color: #434f54;\">&lt;&lt;<\/span> <span style=\"color: #000000;\">CS20<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #434f54;\">|<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1<\/span> <span style=\"color: #434f54;\">&lt;&lt;<\/span> <span style=\"color: #000000;\">CS21<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n \u00a0<span style=\"color: #000000;\">TIMSK2<\/span> <span style=\"color: #434f54;\">|=<\/span> <span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1<\/span> <span style=\"color: #434f54;\">&lt;&lt;<\/span> <span style=\"color: #000000;\">OCIE2A<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n \u00a0<span style=\"color: #000000;\">OCR2A<\/span> <span style=\"color: #434f54;\">=<\/span> <span style=\"color: #000000;\">250<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ 1 ms<\/span>\r\n \u00a0<span style=\"color: #d35400;\">pinMode<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">CLK<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #00979c;\">INPUT<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span>\r\n \u00a0<span style=\"color: #d35400;\">pinMode<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">DT<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #00979c;\">INPUT<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n\r\n<span style=\"color: #00979c;\">void<\/span> <span style=\"color: #5e6d03;\">loop<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">{<\/span>\r\n \u00a0<span style=\"color: #5e6d03;\">if<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">enc<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1<\/span><span style=\"color: #000000;\">)<\/span> <span style=\"color: #434f54;\">!=<\/span> <span style=\"color: #000000;\">enc_data_old<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">{<\/span><span style=\"color: #000000;\">enc_data_old<\/span> <span style=\"color: #434f54;\">=<\/span> <span style=\"color: #000000;\">enc<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span>\r\n \u00a0<b><span style=\"color: #d35400;\">Serial<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">println<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">enc<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span>\r\n \u00a0<span style=\"color: #000000;\">}<\/span>\r\n \u00a0<span style=\"color: #000000;\">}<\/span>\r\n\r\n<span style=\"color: #00979c;\">int<\/span> <span style=\"color: #000000;\">enc<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #00979c;\">bool<\/span> <span style=\"color: #000000;\">byte_s<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">{<\/span>\r\n \u00a0<span style=\"color: #000000;\">enc_a<\/span> <span style=\"color: #434f54;\">=<\/span> <span style=\"color: #d35400;\">digitalRead<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">CLK<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n \u00a0<span style=\"color: #000000;\">_delay_us<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">500<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n \u00a0<span style=\"color: #000000;\">enc_b<\/span> <span style=\"color: #434f54;\">=<\/span> <span style=\"color: #d35400;\">digitalRead<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">DT<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span>\r\n \u00a0\r\n \u00a0\u00a0<span style=\"color: #5e6d03;\">if<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #434f54;\">!<\/span><span style=\"color: #000000;\">enc_a<\/span><span style=\"color: #000000;\">)<\/span> <span style=\"color: #434f54;\">&amp;&amp;<\/span> <span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">enc_old_a<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">{<\/span>\r\n \u00a0\u00a0\u00a0<span style=\"color: #5e6d03;\">if<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">enc_b<\/span><span style=\"color: #000000;\">)<\/span> <span style=\"color: #000000;\">{<\/span><span style=\"color: #000000;\">enc_data<\/span><span style=\"color: #434f54;\">++<\/span><span style=\"color: #000000;\">;<\/span><span style=\"color: #000000;\">}<\/span> \u00a0\u00a0\r\n \u00a0\u00a0\u00a0\u00a0<span style=\"color: #5e6d03;\">else<\/span> <span style=\"color: #000000;\">{<\/span><span style=\"color: #000000;\">enc_data<\/span><span style=\"color: #434f54;\">--<\/span><span style=\"color: #000000;\">;<\/span><span style=\"color: #000000;\">}<\/span><span style=\"color: #000000;\">}<\/span> \u00a0\u00a0\r\n \u00a0\u00a0\u00a0<span style=\"color: #000000;\">enc_old_a<\/span> <span style=\"color: #434f54;\">=<\/span> <span style=\"color: #000000;\">enc_a<\/span><span style=\"color: #000000;\">;<\/span>\r\n <span style=\"color: #5e6d03;\">if<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">byte_s<\/span> <span style=\"color: #434f54;\">==<\/span> <span style=\"color: #000000;\">0<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">{<\/span><span style=\"color: #000000;\">enc_data<\/span> <span style=\"color: #434f54;\">=<\/span> <span style=\"color: #000000;\">0<\/span><span style=\"color: #000000;\">;<\/span><span style=\"color: #000000;\">}<\/span>\r\n \u00a0\u00a0\u00a0<span style=\"color: #5e6d03;\">return<\/span> <span style=\"color: #000000;\">enc_data<\/span><span style=\"color: #000000;\">;<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n\r\n<span style=\"color: #000000;\">ISR<\/span> <span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">TIMER2_COMPA_vect<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">{<\/span><span style=\"color: #000000;\">enc<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span><span style=\"color: #000000;\">}<\/span>\r\n\r\n<\/pre>\n<p>\u041f\u0435\u0440\u0438\u043e\u0434 \u043e\u043f\u0440\u043e\u0441\u0430 \u0432\u044b\u0445\u043e\u0434\u043e\u0432 CLK \u0438 DT 1 \u043c\u0441. \u041f\u0440\u0438 \u043f\u0440\u0438 \u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u0440\u0443\u0447\u043a\u0438 \u044d\u043d\u043a\u043e\u0434\u0435\u0440\u0430 \u0432 \u043c\u043e\u043d\u0438\u0442\u043e\u0440 \u043f\u043e\u0440\u0442\u0430 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <span style=\"color: #000000;\">enc<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1<\/span><span style=\"color: #000000;\">). \u0414\u043b\u044f \u043e\u0431\u043d\u0443\u043b\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 enc(0).<\/span><\/p>\n<p><a href=\"http:\/\/rcl-radio.ru\/wp-content\/uploads\/2020\/08\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-\u043e\u0442-2020-08-24-165847.png\" class=\"highslide-image\" onclick=\"return hs.expand(this);\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83121\" src=\"http:\/\/rcl-radio.ru\/wp-content\/uploads\/2020\/08\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-\u043e\u0442-2020-08-24-165847.png\" alt=\"\" width=\"208\" height=\"329\" srcset=\"http:\/\/rcl-radio.ru\/wp-content\/uploads\/2020\/08\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-\u043e\u0442-2020-08-24-165847.png 208w, http:\/\/rcl-radio.ru\/wp-content\/uploads\/2020\/08\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-\u043e\u0442-2020-08-24-165847-200x316.png 200w\" sizes=\"auto, (max-width: 208px) 100vw, 208px\" \/><\/a>\u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"http:\/\/rcl-radio.ru\/wp-content\/uploads\/2020\/08\/ENC-1.zip\">ENC<\/a>\u00a0(\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0443\u044e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u043a\u0435\u0442\u0447\u0430 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0448\u0435).<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><span style=\"color: #5e6d03;\">#include<\/span> <span style=\"color: #434f54;\">&lt;<\/span><span style=\"color: #000000;\">ENC<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">h<\/span><span style=\"color: #434f54;\">&gt; \/\/ http:\/\/rcl-radio.ru\/wp-content\/uploads\/2020\/08\/ENC-1.zip<\/span>\r\n\r\n<span style=\"color: #00979c;\">int<\/span> <span style=\"color: #000000;\">data_old<\/span><span style=\"color: #000000;\">;<\/span>\r\n\r\n<span style=\"color: #000000;\">ENC<\/span> <span style=\"color: #000000;\">enc<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">8<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #000000;\">9<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">; \/\/ D8, D9 \/ DT, CLK<\/span>\r\n\r\n<span style=\"color: #00979c;\">void<\/span> <span style=\"color: #5e6d03;\">setup<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">{<\/span>\r\n \u00a0<b><span style=\"color: #d35400;\">Serial<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">begin<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">9600<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n\r\n<span style=\"color: #00979c;\">void<\/span> <span style=\"color: #5e6d03;\">loop<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">{<\/span>\r\n \u00a0<span style=\"color: #5e6d03;\">if<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">enc<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">data<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1<\/span><span style=\"color: #000000;\">)<\/span> <span style=\"color: #434f54;\">!=<\/span> <span style=\"color: #000000;\">data_old<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">{<\/span>\r\n \u00a0\u00a0\u00a0<span style=\"color: #000000;\">data_old<\/span> <span style=\"color: #434f54;\">=<\/span> <span style=\"color: #000000;\">enc<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">data<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span>\r\n \u00a0\u00a0\u00a0<b><span style=\"color: #d35400;\">Serial<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">println<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">enc<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">data<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;\r\n<\/span>\/\/ <span style=\"color: #000000;\">enc<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">data<\/span><span style=\"color: #000000;\">(0<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">; \/\/ \u043e\u0431\u043d\u0443\u043b\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/span>\r\n  <span style=\"color: #000000;\">}<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n\r\n<span style=\"color: #000000;\">ISR<\/span> <span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">TIMER2_COMPA_vect<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">{<\/span><span style=\"color: #000000;\">enc<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">data<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span><span style=\"color: #000000;\">}<\/span>\r\n\r\n<\/pre>\n<p>\u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0446\u0438\u0444\u0440\u043e\u0432\u044b\u0435 \u0432\u0445\u043e\u0434\u044b D2 &#8230; D13 (Arduino Nano)<\/p>\n<p><a href=\"http:\/\/rcl-radio.ru\/wp-content\/uploads\/2020\/08\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-\u043e\u0442-2020-08-24-171443.png\" class=\"highslide-image\" onclick=\"return hs.expand(this);\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83123\" src=\"http:\/\/rcl-radio.ru\/wp-content\/uploads\/2020\/08\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-\u043e\u0442-2020-08-24-171443.png\" alt=\"\" width=\"432\" height=\"327\" srcset=\"http:\/\/rcl-radio.ru\/wp-content\/uploads\/2020\/08\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-\u043e\u0442-2020-08-24-171443.png 432w, http:\/\/rcl-radio.ru\/wp-content\/uploads\/2020\/08\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-\u043e\u0442-2020-08-24-171443-200x151.png 200w\" sizes=\"auto, (max-width: 432px) 100vw, 432px\" \/><\/a><\/p>\n<p>\u0424\u043e\u0440\u0443\u043c &#8212; <a href=\"http:\/\/forum.rcl-radio.ru\/viewtopic.php?id=196\">http:\/\/forum.rcl-radio.ru\/viewtopic.php?id=196<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>KY-040 \u042d\u043d\u043a\u043e\u0434\u0435\u0440\u044b KY-040 \u0447\u0430\u0441\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442 \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 Arduino. KY-040 \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0432 \u0432\u0438\u0434\u0435 \u043c\u043e\u0434\u0443\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u043b\u0430\u0442\u044b \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u044d\u043d\u043a\u043e\u0434\u0435\u0440 \u0438 3 \u043f\u043e\u0434\u0442\u044f\u0433\u0438\u0432\u0430\u044e\u0449\u0438\u0445 (\u043a +5 \u0412) \u0440\u0435\u0437\u0438\u0441\u0442\u043e\u0440\u0430 \u043d\u043e\u043c\u0438\u043d\u0430\u043b\u043e\u043c 10 \u043a\u041e\u043c. \u041f\u0440\u0438 \u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u0440\u0443\u0447\u043a\u0438 \u043c\u043e\u0434\u0443\u043b\u044f \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0432\u0430 \u0441\u0438\u0433\u043d\u0430\u043b\u0430 (A \u0438 B), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u043d\u044b \u043f\u043e \u0444\u0430\u0437\u0435.\u00a0 \u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u0441\u0438\u0433\u043d\u0430\u043b \u0410 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":83119,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[239],"tags":[],"class_list":["post-83118","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino"],"views":5170,"_links":{"self":[{"href":"http:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts\/83118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=83118"}],"version-history":[{"count":4,"href":"http:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts\/83118\/revisions"}],"predecessor-version":[{"id":111214,"href":"http:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts\/83118\/revisions\/111214"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/media\/83119"}],"wp:attachment":[{"href":"http:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=83118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=83118"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=83118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}