아두이노 키패드 예제 - adu-ino kipaedeu yeje

 위 그림은 가로 4줄, 세로 4줄의 전선을 이용하여 4X4=16개의 접점을 스위치처럼 구분하여 인식함으로써 16가지 입력을 구분하여 처리할 수 있는 입력장치의 예이다. 즉,1번 버튼을 누르면 8번핀과 4번핀,  2번 버튼을 을 누르면 8번핀과 3번핀이 쇼트되므로 8개 핀이 어떻게 쇼트되어 연결되는지 check하면 16개 버튼중 어느 버튼을 눌렀는지 확인할 수 있다.

The keypad is a set of buttons arranged in rows and columns (called matrix). Each button is called key

Keypad has various types. Two popular types for DIY projects are keypad 3x4 (12 keys) and keypad 4x4 (16 keys).

Keypad pins are divided into two groups: row and column.

Keypad 3x4 has 7 pins: 4 row-pins (R1, R2, R3, R4) and 3 column-pin (C1, C2, C3).

Keypad 4x4 has 8 pins: 4 row-pins (R1, R2, R3, R4) and 4 column-pin (C1, C2, C3, C4).

This section is the in-depth knowledge. DON'T worry if you don't understand. Ignore this section if it overloads you, and come back in another day. Keep reading the next sections.

The process of detecting the key pressing is called scanning keypad.

It is called “scanning” because it checks one key by one key.

Row-pins are connected to Arduino's output pins

Column pins are connected to Arduino's input pins (INPUT_PULLUP, in this state, the value of the input pin is HIGH if the key is not pressed).

For each row:

  • Sets all row-pins is HIGH.

  • Sets only the current row-pin to LOW.

  • Reads the state of each column.

    • If a column-pin is HIGH ⇒ key at (row, column) is NOT pressed.

    • If a column-pin is LOW ⇒ key at (row, column) is pressed.

  • Repeats the above process for the next row-pins.

※ NOTE THAT:

The above is one of the methods to scan keypad. We can invert all HIGH to LOW and all LOW to HIGH to scan keypad.

Why does keypad is arranged and connected as a matrix? This makes the scanning process complicated. Why do not use each key as an independent button, then the state of the key is simply determined by reading the state of a button?

⇒ As we know, an independent button requires one Arduino's pin and GND. Let's take keypad 4x4 as an example. If we each key as an independent button, it requires 16 Arduino pin for 16 keys plus GND pin. If we arranged a connected key in matrix form, we just need to use 8 Arduino's pin, so we can save Arduino's pin. In short, the answer is: to save the Arduino pins.

반응형

아두이노와 4x4 KeyPad 시리얼 입력 해보기

키패드를 이용해서 아두이노 제어를 해보았습니다.

 

1. 1초간 아두이노 깜빡이기

 

 사용 부품

1) 아두이노 UNO 

2) LED

3) 키패드

 

 

○ 회로 연결

○ 적용 코드

#include <Keypad.h> ////playground.arduino.cc/Code/Keypad/ 에서 다운로드 const byte ROWS = 4; const byte COLS = 4; char hexaKeys[ROWS][COLS] = { {'0','1','2','3'}, {'4','5','6','7'}, {'8','9','a','b'}, {'c','d','e','f'} }; byte rowPins[ROWS] = { 6, 7, 8, 9 }; byte colPins[COLS] = {10, 11, 12, 13}; char customKey; Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); void setup(){ Serial.begin(9600); } void keyPress(); void loop(){ keyPress(); } void keyPress(){ // 키 입력 함수 customKey = customKeypad.getKey(); if(customKey){ //키 입력 신호가 있을때만 작동 Serial.println(customKey); delay(100); } }

 

위 Key Pad 라이브러리는

 

기본적으로 setDebounceTime은 50ms

HoldTime 은 1000ms으로 설정되어 있습니다.

 

바꾸고 싶으시다면, keypad.setDebounceTime(unsgined int 시간)으로 바꾸시면 됩니다~!

 

 

 

○ 키패드 

키패드는 4개의 입력선, 4개의 출력선이 스위치를 통해 연결되어 있다.

아두이노에서 각각의 입력선으로 신호를 보내면 연결된 출력선으로 입력한 신호를 돌려받게 됩니다!

 

 

 

 

○ 키패드를 활용해서 다양한 활용이 가능할 것 같네요 ^^

 

 

 

 

 

반응형

공유하기

게시글 관리

구독하기병아리 개발자의 이야기

'메이커 이야기 > 아두이노' 카테고리의 다른 글

[수위 측정] 아두이노 수위센서 사용방법  (0)2020.02.05[아두이노 랜덤] 완벽한 랜덤 값 생성  (2)2020.02.05[아두이노 LCD 타이머] 아두이노 LCD 화면 제어 _ EP5  (20)2020.02.04[아두이노 가변저항] 아두이노 가변저항으로 LED 컨트롤_EP4  (0)2020.02.02[아두이노 RGB] 아두이노 Color 컨트롤러 만들기_EP3  (0)2020.02.02

Toplist

최신 우편물

태그