<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><h3id="update-tri-layer-state-state-x-y-z"tabindex="-1"><code>update_tri_layer_state(state, x, y, z)</code><aclass="header-anchor"href="#update-tri-layer-state-state-x-y-z"aria-label="Permalink to "`update_tri_layer_state(state, x, y, z)`""></a></h3><p>The other function is <code>update_tri_layer_state(state, x, y, z)</code>. This function is meant to be called from the <ahref="./custom_quantum_functions#layer-change-code"><code>layer_state_set_*</code> functions</a>. This means that any time that you use a keycode to change the layer, this will be checked. So you could use <code>LT(layer, kc)</code> to change the layer and it will trigger the same layer check.</p><p>There are a couple of caveats to this method:</p><ol><li>You cannot access the <code>z</code> layer without having <code>x</code> and <code>y</code> layers on, since if you try to activate just layer <code>z</code>, it will run this code and turn off layer <code>z</code> before you could use it.</li><li>Because layers are processed from the highest number <code>z</code> should be a higher layer than <code>x</code> and <code>y</code> or you may not be able to access it.</li></ol><h4id="example-1"tabindex="-1">Example <aclass="header-anchor"href="#example-1"aria-label="Permalink to "Example""></a></h4><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:#005CC5;--shiki-dark:#79B8FF;">layer_state_t</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> layer_state_set_user</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><spanstyle="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">layer_state_t</span><spanstyle="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> state</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><p>Alternatively, you don't have to immediately "return" the value. This is useful if you want to add multiple tri layers, or if you want to add additional effects.</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:#005CC5;--shiki-dark:#79B8FF;">layer_state_t</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> layer_state_set_user</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><spanstyle="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">layer_state_t</span><spanstyle="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> state</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> state </span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> update_tri_layer_state</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(state, _LOWER, _RAISE, _ADJUST);</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> state </span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> update_tri_layer_state</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(state, _RAISE, _SYMB, _SPECIAL);</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><h2id="setting-the-persistent-default-layer"tabindex="-1">Setting the Persistent Default Layer <aclass="header-anchor"href="#setting-the-persistent-default-layer"aria-label="Permalink to "Setting the Persistent Default Layer""></a></h2><p>Do you want to set the default layer, so that it's retained even after you unplug the board? If so, this is the function for you.</p><p>To use this, you would use <code>set_single_persistent_default_layer(layer)</code>. If you have a name defined for your layer, you can use that instead (such as _QWERTY, _DVORAK or _COLEMAK).</p><p>This will set the default layer, update the persistent settings, and play a tune if you have <ahref="./features/audio">Audio</a> enabled on your board, and the default layer sounds set.</p><p>To configure the default layer sounds, you would want to define this in your <code>config.h</code> file, 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;"> DEFAULT_LAYER_SONGS</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { </span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">SONG</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(QWERTY_SOUND), </span><spanstyle="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span></code></pre></div><divclass="tip custom-block"><pclass="custom-block-title">TIP</p><p>There are a large number of predefined songs in <ahref="https://github.com/qmk/qmk_firmware/blob/master/quantum/audio/song_list.h"target="_blank"rel="noreferrer">quantum/audio/song_list.h</a> that you can use.</p></div><h2id="resetting-the-keyboard"tabindex="-1">Resetting the keyboard <aclass="header-anchor"href="#resetting-the-keyboard"aria-label="Permalink to "Resetting the keyboard""></a></h2><p>There is the <code>QK_REBOOT</code> or <code>QK_RBT</code> quantum keycode that you can use. But if you want to reset the board as part of a macro, rather than hitting a key separately, you can do that.</p><p>And to do so, add <code>soft_reset_keyboard()</code> to your function or macro.</p><h2id="reset-to-bootloader"tabindex="-1">Reset to bootloader <aclass="header-anchor"href="#reset-to-bootloader"aria-label="Permalink to "Reset to bootloader""></a></h2><p>To reset to the bootloader use <code>QK_BOOTLOADER</code> or <code>QK_BOOT</code> keycode or <code>reset_keyboard()</code> function.</p><h2id="wiping-the-eeprom-persistent-storage"tabindex="-1">Wiping the EEPROM (Persistent Storage) <aclass="header-anchor"href="#wiping-the-eeprom-persistent-storage"aria-label="Permalink to "Wiping the EEPROM (Persistent Storage)""></a></h2><p>If you're having issues with Audio, RGB Underglow, backlighting or keys acting weird, then you can reset the EEPROM (persistent setting storage). To force an EEPROM reset, use the <ahref="./quantum_keycodes"><code>EE_CLR</code> keycode</a> or <ahref="./features/bootmagic">Bootmagic Lite</a> functionality. If neither of those are an option, then you can use a custom macro to do so.</p><p>To wipe the EEPROM, run <code>eeconfig_init()</code> from your function or macro to reset most of the settings to default.</p><h2id="tap-random-key"tabindex="-1">Tap random key <aclass="header-anchor"href="#tap-random-key"aria-label="Permalink to "Tap random key""></a></h2><p>If you want to send a random character to the host computer, you can use the <code>tap_random_base64()</code> function. This <ahref="https://en.wikipedia.org/wiki/Pseudorandom_number_generator"target="_blank"rel="noreferrer">pseudorandomly</a> selects a number between 0 and 63, and then sends a key press based on that selection. (0–25 is <code>A</code>–<code>Z</code>, 26–51 is <code>a</code>–<code>z</code>, 52–61 is <code>0</code>–<code>9</code>, 62 is <code>+</code> and 63 is <code>/</code>).</p><divclass="tip custom-block"><pclass="custom-block-title">TIP</p><p>Needless to say, but this is <em>not</em> a cryptographically secure method of generating random Base64 keys or passwords.</p></div><h2id="software-timers"tabindex="-1">Software Timers <aclass="header-anchor"href="#software-timers"aria-label="Permalink to "Software Timers""></a></h2><p>It's possible to start timers and read values for time-specific events. Here's an example:</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;">static</span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;"> uint16_t</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> key_timer;</span></span>