
รหัสสินค้า | cm-0047 |
หมวดหมู่ | สวิตซ์ |
ราคาปกติ | |
ลดเหลือ | 20.00 บาท |
สถานะสินค้า | พร้อมส่ง |
แก้ไขล่าสุด | 8 ก.พ. 2561 |
ความพึงพอใจ | ยังไม่มีความคิดเห็น |
จำนวน | ชิ้น |
With the keypad facing up so that the keys are up and facing you, from left to right, the 1st 4 pins are the row pins and the last 4 pins are the column pins.
When connecting the pins to the arduino board, we connect them to the digital output pins, D9-D2. We connect the first pin of the keypad to D9, the second pin to D8, the third pin to D7, the fourth pin to D6, the fifth pin to D5, the sixth pin to D4, the seventh pin to D3, and the eighth pin to D2.
รายละเอียดการเชื่อมต่ออุปกรณ์
Keypad Pin | Connects to Arduino Pin... |
1 | D9 |
2 | D8 |
3 | D7 |
4 | D6 |
5 | D5 |
6 | D4 |
7 | D3 |
8 | D2 |
Here you visually see all the connections that were written above.
Now that we have the physical setup, all we need now is the code.
Before you can run this, you have to import the Keypad library and then once you import it, then you can enter it into your program. Once it's entered into your program, you should see the line #include . If you do not see this, that means that the Keypad library has not been successfully put into your code and it won't work.
You can download the Keypad library here: Keypad Library. When you download, change the name to folder to something other than Keypad. If the folder and the file you are importing have the same name, it won't work.
วีดีโอแนะนำการใช้งานอุปกรณ์
โค้ดตัวอย่างการใช้งานกับบอร์ด Arduino
/*4x4 Matrix Keypad connected to Arduino
This code prints the key pressed on the keypad to the serial port*/
#include <Keypad.h>
const byte numRows= 4; //number of rows on the keypad
const byte numCols= 4; //number of columns on the keypad
//keymap defines the key pressed according to the row and columns just as appears on the keypad
char keymap[numRows][numCols]= {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
//Code that shows the the keypad connections to the arduino terminals
byte rowPins[numRows] = {9,8,7,6}; //Rows 0 to 3
byte colPins[numCols]= {5,4,3,2}; //Columns 0 to 3
//initializes an instance of the Keypad class
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
void setup() {
Serial.begin(9600);
}
//If key is pressed, this key is stored in 'keypressed' variable
//If key is not equal to 'NO_KEY', then this key is printed out
//if count=17, then count is reset back to 0 (this means no key is pressed during the whole keypad scan process
void loop() {
char keypressed = myKeypad.getKey();
if (keypressed != NO_KEY) {
Serial.print(keypressed);
}
}
With this code, once we press a key on the keypad, it should show up on the serial monitor of the arduino software once the code is compiled and uploaded to the arduino board.
หน้าที่เข้าชม | 167,929 ครั้ง |
ผู้ชมทั้งหมด | 80,523 ครั้ง |
เปิดร้าน | 2 ก.ย. 2559 |
ร้านค้าอัพเดท | 20 เม.ย. 2561 |