คีย์แพดสำหรับป้อนข้อมูลให้ Arduino ขนาด 3X4
#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] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 3, 2}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
Serial.begin(9600);
pinMode(5, OUTPUT);
}
void loop() {
digitalWrite(5,LOW);
char key = keypad.getKey();
if (key) {
digitalWrite(5,HIGH);
Serial.println(key);
delay(100);
}
}