<spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ENCODER_B_PINS</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { B13 }</span></span></code></pre></div><p>Each PAD_A/B variable defines an array so multiple encoders can be defined, e.g.:</p><divclass="language-c vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">c</span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ENCODER_A_PINS</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { encoder1a, encoder2a }</span></span>
<spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ENCODER_B_PINS</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { encoder1b, encoder2b }</span></span></code></pre></div><p>If your encoder's clockwise directions are incorrect, you can swap the A & B pad definitions. They can also be flipped with a define:</p><divclass="language-c vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">c</span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ENCODER_DIRECTION_FLIP</span></span></code></pre></div><p>Additionally, the resolution, which defines how many pulses the encoder registers between each detent, can be defined with:</p><divclass="language-c vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">c</span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ENCODER_RESOLUTION</span><spanstyle="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 4</span></span></code></pre></div><p>It can also be defined per-encoder, by instead defining:</p><divclass="language-c vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">c</span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ENCODER_RESOLUTIONS</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { </span><spanstyle="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><spanstyle="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span></code></pre></div><p>For 4× encoders you also can assign default position if encoder skips pulses when it changes direction. For example, if your encoder send high level on both pins by default, define this:</p><divclass="language-c vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">c</span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ENCODER_DEFAULT_POS</span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;"> 0x</span><spanstyle="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span></span></code></pre></div><h2id="split-keyboards"tabindex="-1">Split Keyboards <aclass="header-anchor"href="#split-keyboards"aria-label="Permalink to "Split Keyboards""></a></h2><p>If you are using different pinouts for the encoders on each half of a split keyboard, you can define the pinout (and optionally, resolutions) for the right half like this:</p><divclass="language-c vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">c</span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ENCODER_A_PINS_RIGHT</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { encoder1a, encoder2a }</span></span>
<spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ENCODER_RESOLUTIONS_RIGHT</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { </span><spanstyle="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><spanstyle="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span></code></pre></div><p>If the <code>_RIGHT</code> definitions aren't specified in your <code>config.h</code>, then the non-<code>_RIGHT</code> versions will be applied to both sides of the split.</p><p>Additionally, if one side does not have an encoder, you can specify <code>{}</code> for the pins/resolution -- for example, a split keyboard with only a right-side encoder:</p><divclass="language-c vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">c</span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ENCODER_A_PINS</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { }</span></span>
<spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ENCODER_RESOLUTIONS_RIGHT</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { </span><spanstyle="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span></code></pre></div><divclass="warning custom-block"><pclass="custom-block-title">WARNING</p><p>Keep in mind that whenver you change the encoder resolution, you will need to reflash the half that has the encoder affected by the change.</p></div><h2id="encoder-map"tabindex="-1">Encoder map <aclass="header-anchor"href="#encoder-map"aria-label="Permalink to "Encoder map {#encoder-map}""></a></h2><p>Encoder mapping may be added to your <code>keymap.c</code>, which replicates the normal keyswitch layer handling functionality, but with encoders. Add this to your keymap's <code>rules.mk</code>:</p><divclass="language-make vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">make</span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">ENCODER_MAP_ENABLE = yes</span></span></code></pre></div><p>Your <code>keymap.c</code> will then need an encoder mapping defined (for four layers and two encoders):</p><divclass="language-c vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">c</span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">#if</span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;"> defined</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ENCODER_MAP_ENABLE</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">#endif</span></span></code></pre></div><divclass="tip custom-block"><pclass="custom-block-title">TIP</p><p>This should only be enabled at the keymap level.</p></div><p>Using encoder mapping pumps events through the normal QMK keycode processing pipeline, resulting in a <em>keydown/keyup</em> combination pushed through <code>process_record_xxxxx()</code>. To configure the amount of time between the encoder "keyup" and "keydown", you can add the following to your <code>config.h</code>:</p><divclass="language-c vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">c</span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ENCODER_MAP_KEY_DELAY</span><spanstyle="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span></span></code></pre></div><divclass="tip custom-block"><pclass="custom-block-title">TIP</p><p>By default, the encoder map delay matches the value of <code>TAP_CODE_DELAY</code>.</p></div><h2id="callbacks"tabindex="-1">Callbacks <aclass="header-anchor"href="#callbacks"aria-label="Permalink to "Callbacks""></a></h2><divclass="tip custom-block"><pclass="custom-block-title">TIP</p><p><ahref="https://github.com/qmk/qmk_firmware/blob/master/quantum/encoder.c#L79-"target="_blank"rel="noreferrer"><strong>Default Behaviour</strong></a>: all encoders installed will function as volume up (<code>KC_VOLU</code>) on clockwise rotation and volume down (<code>KC_VOLD</code>) on counter-clockwise rotation. If you do not wish to override this, no further configuration is necessary.</p></div><p>If you would like the alter the default behaviour, and are not using <code>ENCODER_MAP_ENABLE = yes</code>, the callback functions can be inserted into your <code><keyboard>.c</code>:</p><divclass="language-c vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">c</span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">bool</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> encoder_update_kb</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">uint8_t</span><spanstyle="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> index</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">bool</span><spanstyle="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> clockwise</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><spanstyle="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> false</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /* Don't process further events if user function exists and returns false */</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><divclass="warning custom-block"><pclass="custom-block-title">WARNING</p><p>If you return <code>true</code> in the keymap level <code>_user</code> function, it will allow the keyboard/core level encoder code to run on top of your own. Returning <code>false</code> will override the keyboard level function, if setup correctly. This is generally the safest option to avoid confusion.</p></div><h2id="hardware"tabindex="-1">Hardware <aclass="header-anchor"href="#hardware"aria-label="Permalink to "Hardware""></a></h2><p>The A an B lines of the encoders should be wired directly to the MCU, and the C/common lines should be wired to ground.</p><h2id="multiple-encoders"tabindex="-1">Multiple Encoders <aclass="header-anchor"href="#multiple-encoders"aria-label="Permalink to "Multiple Encoders""></a></h2><p>Multiple encoders may share pins so long as each encoder has a distinct pair of pins when the following conditions are met:</p><ul><li>using detent encoders</li><li>pads must be high at the detent stability point which is called 'default position' in QMK</li><li>no more than two encoders sharing a pin can be turned at the same time</li></ul><p>For example you can support two encoders using only 3 pins like this</p><divclass="language- vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang"></span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><span>#define ENCODER_A_PINS { B1, B1 }</span></span>
<spanclass="line"><span>#define ENCODER_B_PINS { B2, B3 }</span></span></code></pre></div><p>You could even support three encoders using only three pins (one per encoder) however in this configuration, rotating two encoders which share pins simultaneously will often generate incorrect output. For example:</p><divclass="language- vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang"></span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><span>#define ENCODER_A_PINS { B1, B1, B2 }</span></span>
<spanclass="line"><span>#define ENCODER_B_PINS { B2, B3, B3 }</span></span></code></pre></div><p>Here rotating Encoder 0 <code>B1 B2</code> and Encoder 1 <code>B1 B3</code> could be interpreted as rotating Encoder 2 <code>B2 B3</code> or <code>B3 B2</code> depending on the timing. This may still be a useful configuration depending on your use case</p></div></div></main><footerclass="VPDocFooter"data-v-39a288b8data-v-09de1c0f><!--[--><!--]--><!----><navclass="prev-next"data-v-09de1c0f><divclass="pager"data-v-09de1c0f><aclass="VPLink link pager-link prev"href="/features/dip_switch"data-v-09de1c0f><!--[--><spanclass="desc"data-v-09de1c0f>Previous page</span><spanclass="title"data-v-09de1c0f>DIP Switch</span><!--]--></a></div><divclass="pager"data-v-09de1c0f><aclass="VPLink link pager-link next"href="/features/haptic_feedback"data-v-09de1c0f><!--[--><spanclass="desc"data-v-09de1c0f>Next page</span><spanclass="title"data-v-09de1c0f>Haptic Feedback</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><!----><!--[--><!--]--></div></div>