아두이노
아두이노 4x4 keypad Test
hjh1023
2020. 9. 8. 10:55
반응형
playground.arduino.cc/Code/Keypad/
Arduino Playground - Keypad Library
#include const byte ROWS = 4; //four rows const byte COLS = 3; //three columns char keys[ROWS][COLS] = { {'1','2','3'}, {'4','5','6'}, {'7','8','9'}, {'#','0','*'} }; byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
playground.arduino.cc
에서 keypad.zip
다운
#include <Keypad.h>
const byte ROWS = 4; // 행(rows) 개수
const byte COLS = 4; // 열(columns) 개수
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {6, 7, 8, 9}; // R1, R2, R3, R4 단자가 연결된 아두이노 핀 번호
byte colPins[COLS] = {5, 4, 3, 2}; // C1, C2, C3, C4 단자가 연결된 아두이노 핀 번호
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
Serial.begin(115200);
}
void loop() {
char key = keypad.getKey();
if (key) {
Serial.println(key);
}
}
#include <Keypad.h>
const byte ROWS = 4; // 행(rows) 개수
const byte COLS = 4; // 열(columns) 개수
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {6, 7, 8, 9}; // R1, R2, R3, R4 단자가 연결된 아두이노 핀 번호
byte colPins[COLS] = {5, 4, 3, 2}; // C1, C2, C3, C4 단자가 연결된 아두이노 핀 번호
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
Serial.begin(115200);
}
void loop() {
char key = keypad.getKey();
if (key) {
switch(key) {
case 'A':
Serial.println("Hello?");
break;
case 'B':
Serial.println("I love you.");
break;
case 'C':
Serial.println("안녕하세요.");
break;
default:
Serial.println(key);
break;
}
}
}
선은 많지만 연결자체는 쉬운편이다..!
반응형