{"id":913,"date":"2018-01-15T23:34:47","date_gmt":"2018-01-15T22:34:47","guid":{"rendered":"http:\/\/yarogniew.net\/arduino\/?p=913"},"modified":"2021-04-07T15:53:08","modified_gmt":"2021-04-07T13:53:08","slug":"rotary-encoder-w-akcji","status":"publish","type":"post","link":"https:\/\/arduino.net.pl\/index.php\/rotary-encoder-w-akcji\/","title":{"rendered":"Enkoder Rotacyjny\u00a0czyli Rotary Encoder &#8211; cyfrowy prze\u0142\u0105cznik"},"content":{"rendered":"\n<p>Dzi\u015b przyjrzymy si\u0119 urz\u0105dzeniu, kt\u00f3re nazywa si\u0119 <strong>Enkoder Rotacyjny<\/strong>&nbsp;(ang. Rotary Encoder)<\/p>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img decoding=\"async\" src=\"https:\/\/arduino.net.pl\/wp-content\/uploads\/2018\/01\/RotaryEncoder_pic_resistor-768x524.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>Kupi\u0142em go u Alice w Chinach: <a href=\"https:\/\/www.ebay.com\/itm\/Rotary-Encoder-Module-Brick-Sensor-Development-Board-For-Arduino-\/310702417391?hash=item48574ea5ef\">Rotary-Encoder-Module-Brick-Sensor-Development-Board-For-Arduino<\/a><br>Przejrza\u0142em kilkana\u015bcie stron z opisami dzia\u0142ania enkodera i wybra\u0142em witryn\u0119 <a rel=\"noopener\" href=\"http:\/\/howtomechatronics.com\/tutorials\/arduino\/rotary-encoder-works-use-arduino\/\" target=\"_blank\">Dejana Nedelkovskiego<\/a>. Program troch\u0119 zmodyfikowa\u0142em dodaj\u0105c SW, czyli przycisk, kt\u00f3ry w tym wypadku s\u0142u\u017cy do zerowania zliczanych krok\u00f3w. Jak na zdj\u0119ciu nale\u017cy pin wyj\u015bciowy modu\u0142u (SW) podci\u0105gn\u0105\u0107 pod VCC (+5V) rezystorem 10k. <\/p>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img decoding=\"async\" src=\"https:\/\/arduino.net.pl\/wp-content\/uploads\/2018\/01\/RotaryEncoder_UNO-768x523.png\" alt=\"\"\/><\/figure>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; light: false; title: Kod:; toolbar: true; notranslate\" title=\"Kod:\">\n&lt;pre class=&quot;wp-block-syntaxhighlighter-code&quot;&gt;\n\/* Arduino Rotary Encoder Tutorial\n*\n* by Dejan Nedelkovski, www.HowToMechatronics.com\n*\n*\/\n\n#define outputA 6\n#define outputB 7\n#define SW 5\n\nint counter = 0;\nint aState;\nint aLastState;\n\/\/int SWread;\n\/\/int aLastSWstate;\n\nvoid setup() {\npinMode (outputA,INPUT);\npinMode (outputB,INPUT);\npinMode (SW,INPUT);\n\nSerial.begin (9600);\n\/\/ Reads the initial state of the outputA\naLastState = digitalRead(outputA);\n\/\/aLastSWstate = digitalRead(SW);\n}\n\nvoid loop() {\n\nif (!digitalRead(SW))\n{\ncounter=0;\nSerial.println(&quot;Reset.Position: 0&quot;);\ndelay(500);\n}\n\naState = digitalRead(outputA); \/\/ Reads the &quot;current&quot; state of the outputA\n\/\/ If the previous and the current state of the outputA are different, that means a Pulse has occured\nif (aState != aLastState){\n\/\/ If the outputB state is different to the outputA state, that means the encoder is rotating clockwise\nif (digitalRead(outputB) != aState) {\ncounter ++;\n} else {\ncounter --;\n}\nSerial.print(&quot;Position: &quot;);\nSerial.println(counter);\n\n}\naLastState = aState; \/\/ Updates the previous state of the outputA with the current state\n}\n&lt;\/pre&gt;\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">Linki:<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/curiousscientist.tech\/blog\/arduino-menu-navigation-rotary-encoder\">https:\/\/curiousscientist.tech\/blog\/arduino-menu-navigation-rotary-encoder<\/a><\/li><li><a href=\"http:\/\/www.gammon.com.au\/forum\/?id=11130\">http:\/\/www.gammon.com.au\/forum\/?id=11130<\/a><\/li><li><a rel=\"noopener\" href=\"http:\/\/henrysbench.capnfatz.com\/henrys-bench\/arduino-sensors-and-input\/keyes-ky-040-arduino-rotary-encoder-user-manual\/\" target=\"_blank\">Henrys Bench<\/a><\/li><li><a rel=\"noopener\" href=\"https:\/\/bigdanzblog.wordpress.com\/2014\/08\/16\/using-a-ky040-rotary-encoder-with-arduino\/\" target=\"_blank\">Big Dan<\/a><\/li><li><a rel=\"noopener\" href=\"https:\/\/www.youtube.com\/watch?v=6y7zixTILJk&amp;t=503s\" target=\"_blank\">Elektroprzewodnik<\/a><\/li><li><a rel=\"noopener\" href=\"https:\/\/www.youtube.com\/watch?v=o4SRpQGc6tc\" target=\"_blank\">elektronik2313<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Dzi\u015b przyjrzymy si\u0119 urz\u0105dzeniu, kt\u00f3re nazywa si\u0119 Enkoder Rotacyjny&nbsp;(ang. Rotary Encoder) Kupi\u0142em go u Alice w Chinach: Rotary-Encoder-Module-Brick-Sensor-Development-Board-For-ArduinoPrzejrza\u0142em kilkana\u015bcie stron z opisami dzia\u0142ania enkodera i wybra\u0142em witryn\u0119 Dejana Nedelkovskiego. Program&#8230;<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[42],"class_list":["post-913","post","type-post","status-publish","format-standard","hentry","category-arduino","tag-rotary_encoder"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/posts\/913","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/comments?post=913"}],"version-history":[{"count":24,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/posts\/913\/revisions"}],"predecessor-version":[{"id":4312,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/posts\/913\/revisions\/4312"}],"wp:attachment":[{"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/media?parent=913"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/categories?post=913"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/tags?post=913"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}