# Using rotary encoder

**URL:** <https://discourse.nodered.org/t/using-rotary-encoder/29775>\
**Category:** General\
**Created:** [9 July 2020 10:21 UTC](https://discourse.nodered.org/t/using-rotary-encoder/29775 "2020-07-09T10:21:04Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [10 July 2020 21:38 UTC](https://discourse.nodered.org/t/using-rotary-encoder/29775/13 "2020-07-10T21:38:30Z")

</div>

More compact version using a function node

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/5/452889c2c2a834241699666b13b1d2f20b68afa6.png)

```auto
[{"id":"2c40d42d.176cbc","type":"debug","z":"dfaf687e.30fb88","name":"STATUS_FUNCTION","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":680,"y":540,"wires":[]},{"id":"e2775f3d.af2bd","type":"change","z":"dfaf687e.30fb88","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"CLK","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":500,"wires":[["c4b142c4.477fe"]]},{"id":"27e7e692.0d532a","type":"change","z":"dfaf687e.30fb88","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"DT","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":580,"wires":[["c4b142c4.477fe"]]},{"id":"c4b142c4.477fe","type":"function","z":"dfaf687e.30fb88","name":"","func":"var CLK;\n\n\nif ((msg['topic']) == 'CLK') {\n CLK = (msg['payload']);\n if (context.keys().includes('DT')) {\n if (CLK != (context.get('DT'))) {\n msg['payload'] = 'clockwise';\n } else {\n msg['payload'] = 'anti-clockwise';\n }\n return msg;\n }\n} else {\n context.set('DT', (msg['payload']));\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":460,"y":540,"wires":[["2c40d42d.176cbc"]]},{"id":"1531b07b.ff934","type":"comment","z":"dfaf687e.30fb88","name":"CLK","info":"","x":270,"y":460,"wires":[]},{"id":"9aa49914.0e8cd8","type":"comment","z":"dfaf687e.30fb88","name":"DT","info":"","x":270,"y":620,"wires":[]},{"id":"a8fe264f.2d9368","type":"rpi-gpio in","z":"dfaf687e.30fb88","name":"","pin":"8","intype":"tri","debounce":"0","read":true,"x":90,"y":500,"wires":[["e2775f3d.af2bd"]]},{"id":"2a16462.f4e30ba","type":"rpi-gpio in","z":"dfaf687e.30fb88","name":"","pin":"10","intype":"tri","debounce":"0","read":true,"x":90,"y":580,"wires":[["27e7e692.0d532a"]]}]

```

---

_[View the full topic](https://discourse.nodered.org/t/using-rotary-encoder/29775)._
