.. note:: Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts. **Why Join?** - **Expert Support**: Solve post-sale issues and technical challenges with help from our community and team. - **Learn & Share**: Exchange tips and tutorials to enhance your skills. - **Exclusive Previews**: Get early access to new product announcements and sneak peeks. - **Special Discounts**: Enjoy exclusive discounts on our newest products. - **Festive Promotions and Giveaways**: Take part in giveaways and holiday promotions. 👉 Ready to explore and create with us? Click [|link_sf_facebook|] and join today! .. _2.1.5_keypad_nodejs: 2.1.5 Keypad ============ Introduction ------------ A keypad is a rectangular array of buttons. In this project, We will use it input characters. Components ---------- .. image:: ../img/list_2.1.5_keypad.png Schematic Diagram ----------------- .. image:: ../img/image315.png .. image:: ../img/image316.png Experimental Procedures ----------------------- **Step 1:** Build the circuit. .. image:: ../img/image186.png **Step 2:** Open the code file. .. raw:: html .. code-block:: cd ~/davinci-kit-for-raspberry-pi/nodejs/ **Step 3:** Run. .. raw:: html .. code-block:: sudo node keypad.js After the code runs, the values of pressed buttons on keypad (button Value) will be printed on the screen. **Code** .. code-block:: js const Gpio = require('pigpio').Gpio; var rowsPins = [18,23,24,25]; var colsPins = [10,6,27,17]; var keys = ["1","2","3","A", "4","5","6","B", "7","8","9","C", "*","0","#","D"]; for(let i=0;i{ col=i; pressed_keys=keys[row*colsPins.length+col]; if(last_key_pressed!=pressed_keys){ console.log(`${pressed_keys}`); } last_key_pressed = pressed_keys; }); } var row=-1; setInterval(() => { row=(row+1)%rowsPins.length; for(let i=0;i { row=(row+1)%rowsPins.length; for(let i=0;i{ col=i; // pressed_keys=keys[row*colsPins.length+col]; // if(last_key_pressed!=pressed_keys){ // console.log(`${pressed_keys}`); // } // last_key_pressed = pressed_keys; }); } Set up interrupt functions for the four column pins, and the variable ``col`` is used to locate the column pins that trigger the rising edge interrupt event. .. code-block:: js pressed_keys=keys[row*colsPins.length+col]; if(last_key_pressed!=pressed_keys){ console.log(`${pressed_keys}`); } last_key_pressed = pressed_keys; There is also a piece of code in the break function to get the specific key value from the ``keys`` matrix according to ``row`` and ``col``. And every time you get a new key value, print the value. Phenomenon Picture ------------------ .. image:: ../img/image188.jpeg