有没谁有4*4键盘的程序,能在显示屏显示的 ?
有没谁有4*4键盘的程序,能在显示屏显示的? #include <Keypad.h>//LingShun lab
#include <Wire.h>
#include <LiquidCrystal_I2C.h> //引用I2C库
//设置LCD1602设备地址,这里的地址是0x3F,一般是0x20,或者0x27,具体看模块手册
LiquidCrystal_I2C lcd(0x3F,16,2);
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){
lcd.init(); // 初始化LCD
lcd.backlight(); //设置LCD背景等亮
Serial.begin(9600);
}
void loop(){
char customKey = customKeypad.getKey();
if (customKey){
Serial.println(customKey);
lcd.setCursor(0,0); //设置显示指针
lcd.print(customKey); //输出字符到LCD1602上
lcd.setCursor(9,1);
lcd.print(" Z.W.F.");
}
}
页:
[1]