• 沒有找到結果。

鍵盤結合

N/A
N/A
Protected

Academic year: 2022

Share "鍵盤結合"

Copied!
5
0
0

加載中.... (立即查看全文)

全文

(1)

鍵盤結合 LCD 作業(使用 virtualbreadboard) 2011.12.5

1. 請說明你的程式要做什麼事。

答:要按鍵盤的﹍﹍﹍鍵時使 LCD 顯示﹍﹍﹍

要按鍵盤的﹍﹍﹍鍵時使 LCD 顯示﹍﹍﹍

請在以下的程式中將要修改的地方用 pdfXViewer 註明。

2. 程式電路圖:

以下程式功能為:按鍵盤的”*”鍵時 LCD 顯示*,按鍵盤的”#”鍵時 LCD 顯示#

1 1

9 9

(2)

#include <LiquidCrystal.h>

#include <Keypad.h>

// initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 7, 8, 9, 10) ;

char keys[rows][cols] = { {'1','2','3'}, {'4','5','6'},

{'7','8','9'}, {'*','0','#'}

};

// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these pins, // eg. ROW0 = Arduino pin2.

byte rowPins[] = { 0, 1, 2, 3 };

// Connect keypad COL0, COL1 and COL2 to these pins, // eg. COL0 = Arduino pin6.

byte colPins[] = { 6, 5, 4 };

//create a new Keypad

Keypad keypad = Keypad(rowPins, colPins, sizeOf(rowPins) , sizeOf(colPins) );

void setup() {

Serial.begin(9600);

lcd.begin(16, 2);

lcd.print("hello, world!");

}

void loop() {

char Key = keypad.getKey();

switch (Key) { case '*':

lcd.setCursor(0, 1);

lcd.print("*");

break;

case '#':

case'1';

lcd.print("1");

case'9';

(3)

lcd.setCursor(0, 1);

lcd.print("#");

break;

case KEY_RELEASED:

Serial.println("Key Released");

break;

default:

if (Key != NO_KEY){

Serial.println(Key);

} }

}

註: Keypad 程式的較簡易寫法(相較於 VBB 提供的程式而言):

#include <Keypad.h>

char keys[rows][cols] = { {'1','2','3'}, {'4','5','6'},

{'7','8','9'}, {'*','0','#'}

lcd.print("9");

(4)

};

// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these pins, // eg. ROW0 = Arduino pin2.

byte rowPins[] = { 0, 1, 2, 3 };

// Connect keypad COL0, COL1 and COL2 to these pins, // eg. COL0 = Arduino pin6.

byte colPins[] = { 6, 5, 4 };

//create a new Keypad

Keypad keypad = Keypad(rowPins, colPins, sizeOf(rowPins) , sizeOf(colPins) );

#define ledPin 13 void setup(){

Serial.begin(9600);

digitalWrite(ledPin, HIGH); // sets the LED on }

void loop(){

char Key = keypad.getKey();

switch (Key) { case '*':

digitalWrite(ledPin, HIGH);

break;

case '#':

digitalWrite(ledPin, LOW);

break;

case KEY_RELEASED:

Serial.println("Key Released");

break;

default:

if (Key != NO_KEY){

Serial.println(Key);

}

} }

(5)

參考文獻

相關文件

[4]放入晶片(或載片僅第一次RIE製程用)按下Control System電腦鍵盤上數字鍵5(Load Wafer To Chamber),會出現確認將晶片傳送至1.ICP或2.RIE選單畫面後,如您要

恩尼格瑪密碼機旋轉盤的工作原理圖,連續按兩次 A 鍵後,電流會流經所有旋轉盤,通 過反射器後分別向反方向流到 G 燈和 C 燈。

[r]

[r]

• 接下來是光的反射,會讓孩子去玩接光遊戲,體 驗光的反射,並融入簡易萬花筒、潛望鏡、雙面 ( 多面

大家或許直覺會認為 finite generated vector space 的 subspace 一定也是 finitely gener- ated.. 這是對的,

也可以使用鍵盤直接在文檔中輸入域。按 Ctrl+F9 組合鍵,插入點位置將出現一個 帶底紋的域標志符號“{}",按一下左鍵,將插入點置於“{

Visual Basic提供了許多控制項介面來處理由鍵盤輸入