Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 6508|回復: 3
打印 上一主題 下一主題

關於-Arduino LCD i2c + 3*4鍵盤 結合

[複製鏈接]
1#
發表於 2015-7-22 14:25:26 | 顯示全部樓層
雖然一年後才回覆此主題,希望依舊能幫助到有需要的人
p.s.有問題請留言給我

#include <LiquidCrystal.h>
#include <Keypad.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// 3x4 Keypad
const byte ROWS = 4; // 4 Rows
const byte COLS = 3; // 3 Columns

// 定義 Keypad 的按鍵
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};

// 定義 Keypad 連到 Arduino 的接腳
byte rowPins[ROWS] = {32, 22, 24, 28}; // 連到 Keypad 的 4 個 Rows: Row0, Row1, Row2, Row3
byte colPins[COLS] = {30, 34, 26};   // 連到 Keypad 的 3 個 Columns: Column0, Column1, Column2

// 建立 Keypad 物件
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );


void setup() {
  Serial.begin(9600);
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  
  
}

void loop() {
   // 讀取 Keypad 的輸入
  char key = keypad.getKey();
  
  // NO_KEY 代表沒有按鍵被按下
  if (key != NO_KEY){
    // 假如有按鍵被按下,就印出按鍵對應的字元
    Serial.println(key);
    lcd.print(key);
  }
}
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-6-10 19:45 , Processed in 0.210477 second(s), 7 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表