4x4薄膜按鍵



取得按鍵輸入值

#include <keypad.h>
#define KEY_ROWS 4
#define KEY_COLS 4
char keys[KEY_ROWS][KEY_COLS]= {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[KEY_ROWS]={13,12,11,10} ;
byte colPins[KEY_COLS]={9,8,7,6} ;
Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,KEY_ROWS,KEY_COLS);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600) ;
}

void loop() {
  // put your main code here, to run repeatedly:
  char key = keypad.getKey() ;

  if(key!=NO_KEY) {
       Serial.println(key) ;
    }
}