连线图:

arduino下4*4键盘使用

/* @file HelloKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact [email protected]
||
|| @description
|| | Demonstrates the simplest use of the matrix Keypad library.
|| #
*/
#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] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9,8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
  Serial.begin(9600);
}
  
void loop(){
  char key = keypad.getKey();
  
  if (key){
    Serial.println(key);
  }
}

 

相关文章:

  • 2022-12-23
  • 2021-12-09
  • 2021-12-02
  • 2021-11-01
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2022-02-01
猜你喜欢
  • 2021-10-19
  • 2021-11-19
  • 2022-02-04
  • 2021-05-01
  • 2021-08-13
  • 2021-10-06
  • 2022-12-23
相关资源
相似解决方案