Using rotary encoder

More compact version using a function node

[{"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"]]}]
1 Like