IoT/Arduino

[아두이노] 키패드 입력받기

반나무 2020. 5. 26. 19:26

#include <Keypad.h>

const byte rows = 4; //four rows
const byte cols = 4; //three columns
char keys[rows][cols] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[rows] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[cols] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );

void setup()
{
  Serial.begin(9600);
}

void loop()
{
 char customKey = customKeypad.getKey();
  if(customKey){
  	Serial.println(customKey);
  }
}
반응형