{"id":43076,"date":"2018-06-20T22:09:51","date_gmt":"2018-06-20T16:09:51","guid":{"rendered":"http:\/\/rcl-radio.ru\/?p=43076"},"modified":"2018-06-20T22:15:38","modified_gmt":"2018-06-20T16:15:38","slug":"%d0%b1%d0%b8%d0%b1%d0%bb%d0%b8%d0%be%d1%82%d0%b5%d0%ba%d0%b0-mstimer2-arduino","status":"publish","type":"post","link":"http:\/\/rcl-radio.ru\/?p=43076","title":{"rendered":"\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 MsTimer2 (Arduino)"},"content":{"rendered":"<p>MsTimer2 \u044d\u0442\u043e \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0430\u044f \u0438 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0441\u043b\u0443\u0436\u0438\u0442 \u00ab\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c\u00bb \u043c\u0435\u0436\u0434\u0443 timer2 \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c. \u041e\u043d\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0443 \u044d\u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0438\u043e\u0434\u0430. \u041e\u043d\u0430 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u00abMsTimer2\u00bb, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u00ab\u0437\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u00bb \u0432 timer2 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432 1 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u0443 (ms).<\/p>\n<p><strong>\u0424\u0443\u043d\u043a\u0446\u0438\u0438:<\/strong><\/p>\n<ul>\n<li>\u0424\u0443\u043d\u043a\u0446\u0438\u044f MsTimer2::set(ms, f) \u0437\u0430\u0434\u0430\u0435\u0442 \u043d\u0443\u0436\u043d\u044b\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0432 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445 (\u043f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442; ms). \u041f\u0440\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u00abf\u00bb. \u0415\u0435 \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u0443\u0441\u0442\u043e\u0439, \u0431\u0435\u0437\u043e \u0432\u0441\u044f\u043a\u0438\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432.<\/li>\n<li>\u0424\u0443\u043d\u043a\u0446\u0438\u044f MsTimer2::start() \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u0435.<\/li>\n<li>\u0424\u0443\u043d\u043a\u0446\u0438\u044f MsTimer2::stop() \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u0435.<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<p>\u041e\u0442\u0441\u0447\u0435\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430:<\/p>\n<pre style=\"background: #0c1021; color: #f8f8f8;\">#include &lt;MsTimer2.h&gt;\r\n\r\nunsigned long s;\r\n\r\n<span style=\"color: #8da6ce;\">void<\/span> setup(){ \r\n  Serial.begin(<span style=\"color: #d8fa3c;\">9600<\/span>);\r\n  MsTimer2<span style=\"color: #fbde2d;\">:<\/span><span style=\"color: #fbde2d;\">:<\/span><span style=\"color: #8da6ce;\">set<\/span>(<span style=\"color: #d8fa3c;\">1000<\/span>, to_Timer); <span style=\"color: #aeaeae;\">\/\/ \u0437\u0430\u0434\u0430\u0435\u043c \u043f\u0435\u0440\u0438\u043e\u0434 1\u0441<\/span>\r\n  MsTimer2<span style=\"color: #fbde2d;\">:<\/span><span style=\"color: #fbde2d;\">:<\/span><span style=\"color: #8da6ce;\">start<\/span>(); <span style=\"color: #aeaeae;\">\/\/ \u0441\u0442\u0430\u0440\u0442 \u0442\u0430\u0439\u043c\u0435\u0440\u0430<\/span>\r\n}\r\n\r\n<span style=\"color: #8da6ce;\">void<\/span> to_Timer(){ <span style=\"color: #aeaeae;\">\/\/\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0442\u0430\u0439\u043c\u0435\u0440\u0430<\/span>\r\n  <span style=\"color: #fbde2d;\">+<\/span><span style=\"color: #fbde2d;\">+<\/span>s; <span style=\"color: #aeaeae;\">\/\/ \u043e\u0442\u0441\u0447\u0435\u0442 1 \u0441<\/span>\r\n}\r\n\r\n<span style=\"color: #8da6ce;\">void<\/span> loop(){\r\n\r\n  Serial.println(s);\r\n  delay(<span style=\"color: #d8fa3c;\">1000<\/span>);\r\n}\r\n<\/pre>\n<p>\u0418\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <strong>s<\/strong> \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u043a\u0430\u0436\u0434\u0443\u044e \u0441\u0435\u043a\u0443\u043d\u0434\u0443.<\/p>\n<p>\u041c\u0438\u0433\u0430\u043d\u0438\u0435 \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434\u043e\u043c:<\/p>\n<pre style=\"background: #0c1021; color: #f8f8f8;\">#include &lt;MsTimer2.h&gt;\r\n\r\nunsigned long s;\r\n\r\n<span style=\"color: #8da6ce;\">void<\/span> setup(){ \r\n  Serial.begin(<span style=\"color: #d8fa3c;\">9600<\/span>);\r\n  pinMode(<span style=\"color: #d8fa3c;\">13<\/span>,OUTPUT);\r\n  MsTimer2<span style=\"color: #fbde2d;\">:<\/span><span style=\"color: #fbde2d;\">:<\/span><span style=\"color: #8da6ce;\">set<\/span>(<span style=\"color: #d8fa3c;\">300<\/span>, to_Timer); <span style=\"color: #aeaeae;\">\/\/ \u0437\u0430\u0434\u0430\u0435\u043c \u043f\u0435\u0440\u0438\u043e\u0434 300 \u043c\u0441<\/span>\r\n  MsTimer2<span style=\"color: #fbde2d;\">:<\/span><span style=\"color: #fbde2d;\">:<\/span><span style=\"color: #8da6ce;\">start<\/span>(); <span style=\"color: #aeaeae;\">\/\/ \u0441\u0442\u0430\u0440\u0442 \u0442\u0430\u0439\u043c\u0435\u0440\u0430<\/span>\r\n}\r\n\r\n<span style=\"color: #8da6ce;\">void<\/span> to_Timer(){ <span style=\"color: #aeaeae;\">\/\/\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0442\u0430\u0439\u043c\u0435\u0440\u0430<\/span>\r\n<span style=\"color: #fbde2d;\">static<\/span> boolean output <span style=\"color: #fbde2d;\">=<\/span> HIGH; <span style=\"color: #aeaeae;\">\/* \u041a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e static \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \r\n\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u0438\u0434\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \r\n\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0438 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438*\/<\/span>\r\n<span style=\"color: #aeaeae;\">\/\/ \u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u0430 boolean \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043e\u0434\u043d\u043e \u0438\u0437 \u0434\u0432\u0443\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439: true \u0438\u043b\u0438 false.<\/span>\r\n digitalWrite(<span style=\"color: #d8fa3c;\">13<\/span>,output); <span style=\"color: #aeaeae;\">\/* \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u043d\u0430 \u043f\u043b\u0430\u0442\u0435 Arduino \u0437\u0430\u0433\u043e\u0440\u0430\u0435\u0442\u0441\u044f\r\n \u0438 \u0433\u0430\u0441\u043d\u0435\u0442 \u0441 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u043c 300 \u043c\u0441*\/<\/span>\r\n output <span style=\"color: #fbde2d;\">=<\/span><span style=\"color: #fbde2d;\">!<\/span> output;\r\n}\r\n\r\n<span style=\"color: #8da6ce;\">void<\/span> loop(){\r\n}\r\n<\/pre>\n<p>\u041e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0442\u0430\u0439\u043c\u0435\u0440\u0430:<\/p>\n<pre style=\"background: #0c1021; color: #f8f8f8;\">#include &lt;MsTimer2.h&gt;\r\n\r\nunsigned long s;\r\n\r\n<span style=\"color: #8da6ce;\">void<\/span> setup(){ \r\n  Serial.begin(<span style=\"color: #d8fa3c;\">9600<\/span>);\r\n  MsTimer2<span style=\"color: #fbde2d;\">:<\/span><span style=\"color: #fbde2d;\">:<\/span><span style=\"color: #8da6ce;\">set<\/span>(<span style=\"color: #d8fa3c;\">1000<\/span>, to_Timer); <span style=\"color: #aeaeae;\">\/\/ \u0437\u0430\u0434\u0430\u0435\u043c \u043f\u0435\u0440\u0438\u043e\u0434 1\u0441<\/span>\r\n  MsTimer2<span style=\"color: #fbde2d;\">:<\/span><span style=\"color: #fbde2d;\">:<\/span><span style=\"color: #8da6ce;\">start<\/span>(); <span style=\"color: #aeaeae;\">\/\/ \u0441\u0442\u0430\u0440\u0442 \u0442\u0430\u0439\u043c\u0435\u0440\u0430<\/span>\r\n}\r\n\r\n<span style=\"color: #8da6ce;\">void<\/span> to_Timer(){ <span style=\"color: #aeaeae;\">\/\/\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0442\u0430\u0439\u043c\u0435\u0440\u0430<\/span>\r\n  <span style=\"color: #fbde2d;\">+<\/span><span style=\"color: #fbde2d;\">+<\/span>s; <span style=\"color: #aeaeae;\">\/\/ \u043e\u0442\u0441\u0447\u0435\u0442 1 \u0441<\/span>\r\n}\r\n\r\n<span style=\"color: #8da6ce;\">void<\/span> loop(){\r\n  <span style=\"color: #fbde2d;\">if<\/span>(s<span style=\"color: #fbde2d;\">=<\/span><span style=\"color: #fbde2d;\">=<\/span><span style=\"color: #d8fa3c;\">60<\/span>){MsTimer2<span style=\"color: #fbde2d;\">:<\/span><span style=\"color: #fbde2d;\">:<\/span><span style=\"color: #8da6ce;\">stop<\/span>();}\r\n  Serial.println(s);\r\n  delay(<span style=\"color: #d8fa3c;\">1000<\/span>);\r\n}\r\n<\/pre>\n<p>\u0422\u0430\u0439\u043c\u0435\u0440 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f s \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u043d\u0430 60.<\/p>\n<hr \/>\n<p><strong>\u0421\u043a\u0430\u0447\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443:\u00a0<a class=\"urllink\" href=\"http:\/\/playground.arduino.cc\/uploads\/Main\/MsTimer2.zip\" rel=\"nofollow\">MsTimer2.zip<\/a><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>MsTimer2 \u044d\u0442\u043e \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0430\u044f \u0438 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0441\u043b\u0443\u0436\u0438\u0442 \u00ab\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c\u00bb \u043c\u0435\u0436\u0434\u0443 timer2 \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c. \u041e\u043d\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0443 \u044d\u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0438\u043e\u0434\u0430. \u041e\u043d\u0430 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u00abMsTimer2\u00bb, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u00ab\u0437\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u00bb \u0432 timer2 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432 1 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u0443 (ms). \u0424\u0443\u043d\u043a\u0446\u0438\u0438: \u0424\u0443\u043d\u043a\u0446\u0438\u044f MsTimer2::set(ms, f) \u0437\u0430\u0434\u0430\u0435\u0442 \u043d\u0443\u0436\u043d\u044b\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0432 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445 (\u043f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442; ms). \u041f\u0440\u0438 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":43063,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[239],"tags":[],"class_list":["post-43076","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino"],"views":9051,"_links":{"self":[{"href":"http:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts\/43076","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=43076"}],"version-history":[{"count":2,"href":"http:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts\/43076\/revisions"}],"predecessor-version":[{"id":43079,"href":"http:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts\/43076\/revisions\/43079"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/media\/43063"}],"wp:attachment":[{"href":"http:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=43076"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=43076"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=43076"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}