const__pageData=JSON.parse('{"title":"How a Keyboard Matrix Works","description":"","frontmatter":{},"headers":[],"relativePath":"how_a_matrix_works.md","filePath":"how_a_matrix_works.md"}');
const_sfc_main={name:"how_a_matrix_works.md"};
const_hoisted_1=/* @__PURE__ */createStaticVNode('<h1id="how-a-keyboard-matrix-works"tabindex="-1">HowaKeyboardMatrixWorks<aclass="header-anchor"href="#how-a-keyboard-matrix-works"aria-label="Permalink to "How a Keyboard Matrix Works""></a></h1><p>Keyboardswitchmatricesarearrangedinrowsandcolumns.Withoutamatrixcircuit,eachswitchwouldrequireitsownwiredirectlytothecontroller.</p><p>Whenthecircuitisarrangedinrowsandcolumns,ifakeyispressed,acolumnwiremakescontactwitharowwireandcompletesacircuit.Thekeyboardcontrollerdetectsthisclosedcircuitandregistersitasakeypress.</p><p>Themicrocontrollerwillbesetupviathefirmwaretosendalogical1tothecolumns,oneatatime,andreadfromtherows,allatonce-thisprocessiscalledmatrixscanning.Thematrixisabunchofopenswitchesthat,bydefault,don'tallowanycurrenttopassthrough-thefirmwarewillreadthisasnokeysbeingpressed.Assoonasyoupressonekeydown,thelogical1thatwascomingfromthecolumnthekeyswitchisattachedtogetspassedthroughtheswitchandtothecorrespondingrow-checkoutthefollowing2x2example:</p><divclass="language-vp-adaptive-theme"><buttontitle="CopyCode"class="copy"></button><spanclass="lang"></span><preclass="shikishiki-themesgithub-lightgithub-darkvp-code"><code><spanclass="line"><span>Column0beingscannedColumn1beingscanned</span></span>\n<spanclass="line"><span>xx</span></span>\n<spanclass="line"><span>col0col1col0col1</span></span>\n<spanclass="line"><span>||||</span></span>\n<spanclass="line"><span>row0---(key0)---(key1)row0---(key0)---(key1)</span></span>\n<spanclass="line"><span>||||</span></span>\n<spanclass="line"><span>row1---(key2)---(key3)row1---(key2)---(key3)</span></span></code></pre></div><p>The<code>x</code>representsthatthecolumn/rowassociatedhasavalueof1,orisHIGH.Here,weseethatnokeysarebeingpressed,sonorowsgetan<code>x</code>.Foronekeyswitch,keepinmindthatonesideofthecontactsisconnectedtoitsrow,andtheother,itscolumn.</p><p>Whenwepress<code>key0</code>,<code>col0</code>getsconnectedto<code>row0</code>,sothevaluesthatthefirmwarereceivesforthatrowis<code>0b01</code>(the<code>0b</code>heremeansthatthisisabitvalue,meaningallofthefollowingdigitsarebits-0or1-andrepresentthekeysinthatcolumn).We'llusethisnotationtoshowwhenakeyswitchhasbeenpressed,toshowthatthecolumnandrowarebeingconnected:</p><divclass="language-vp-adaptive-theme"><buttontitle="CopyCode"class="copy"></button><spanclass="lang"></span><preclass="shikishiki-themesgithub-lightgithub-darkvp-code"><code><spanclass="line"><span>Column0beingscannedColumn1beingscanned</span></span>\n<spanclass="line"><span>xx</span></span>\n<spanclass="line"><span>col0col1col0col1</span></span>\n<spanclass="line"><span>||||</span></span>\n<spanclass="line"><span>xrow0---(-+-0)---(key1)row0---(-+-0)---(key1)</span></span>\n<spanclass="line"><span>||||</span></span>\n<spanclass="line"><span>row1---(key2)---(key3)row1---(key2)---(key3)</span></span></code></pre></div><p>Wecannowseethat<code>row0</code>hasan<code>x</code>,sohasthevalueof1.Asawhole,thedatathefirmwarereceiveswhen<code>key0</code>ispressedis:</p><divclass="language-vp-adaptive-theme"><buttontitle="CopyCode"class="copy"></button><spanclass="lang"></span><preclass="shikishiki-themesgithub-lightgithub-darkvp-code"><code><spanclass="line