<spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;"> bool</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> res </span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> led_update_user</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(led_state);</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // gpio_write_pin sets the pin high for 1 and low for 0.</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // In this example the pins are inverted, setting</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // it low/0 turns it on, and high/1 turns the LED off.</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // This behavior depends on whether the LED is between the pin</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // and VCC or the pin and GND.</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><h3id="example-of-user-led-update-implementation"tabindex="-1">Example of user LED update implementation <aclass="header-anchor"href="#example-of-user-led-update-implementation"aria-label="Permalink to "Example of user LED update implementation""></a></h3><p>This is an incomplete example will play a sound if Caps Lock is turned on or off. It returns <code>true</code> to allow keyboard LED function to maintain their state.</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;">#ifdef</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> AUDIO_ENABLE</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><h2id="host-keyboard-led-state"tabindex="-1">Host keyboard LED state <aclass="header-anchor"href="#host-keyboard-led-state"aria-label="Permalink to "Host keyboard LED state""></a></h2><p>The <code>host_keyboard_led_state()</code> function will report the LED state returned from the host computer as <code>led_t</code>. This is useful for reading the LED state outside <code>led_update_*</code>. For example, you can get the boolean state of Caps Lock from the host 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;">bool</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> caps </span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> host_keyboard_led_state</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">().caps_lock;</span></span></code></pre></div><h2id="led-update-ports"tabindex="-1"><code>led_update_ports()</code><aclass="header-anchor"href="#led-update-ports"aria-label="Permalink to "`led_update_ports()`""></a></h2><p>This function writes the LED state to the actual hardware. Call it manually from your <code>led_update_*()</code> callbacks to modify the handling of the standard keyboard LEDs. For example when repurposing a standard LED indicator as layer indicator.</p><h2id="setting-physical-led-state"tabindex="-1">Setting Physical LED State <aclass="header-anchor"href="#setting-physical-led-state"aria-label="Permalink to "Setting Physical LED State""></a></h2><p>Some keyboard implementations provide convenient methods for setting the state of the physical LEDs.</p><h3id="ergodox-boards"tabindex="-1">Ergodox Boards <aclass="header-anchor"href="#ergodox-boards"aria-label="Permalink to "Ergodox Boards""></a></h3><p>The Ergodox implementations provide <code>ergodox_right_led_1</code>/<code>2</code>/<code>3_on</code>/<code>off()</code> to turn individual LEDs on or off, as well as <code>ergodox_right_led_on</code>/<code>off(uint8_t led)</code> to turn them on or off by their index.</p><p>In addition, it is possible to specify the brightness level of all LEDs with <code>ergodox_led_all_set(uint8_t n)</code>; of individual LEDs with <code>ergodox_right_led_1</code>/<code>2</code>/<code>3_set(uint8_t n)</code>; or by index with <code>ergodox_right_led_set(uint8_t led, uint8_t n)</code>.</p><p>Ergodox boards also define <code>LED_BRIGHTNESS_LO</code> for the lowest brightness and <code>LED_BRIGHTNESS_HI</code> for the highest brightness (which is the default).</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/joystick"data-v-09de1c0f><!--[--><spanclass="desc"data-v-09de1c0f>Previous page</span><spanclass="title"data-v-09de1c0f>Joystick</span><!--]--></a></div><divclass="pager"data-v-09de1c0f><aclass="VPLink link pager-link next"href="/features/midi"data-v-09de1c0f><!--[--><spanclass="desc"data-v-09de1c0f>Next page</span><spanclass="title"data-v-09de1c0f>MIDI</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><!----><!--[--><!--]--></div></div>