http://coopermaa2nd.blogspot.tw/2011/02/arduino-serial-led.html
內文提到使用
switch (inByte)這指令來判斷按下的鍵盤按鈕為何?這下對於特殊的ASCII就會有疑惑了,比如說上下左右呢?
果然網路上的資料真多,一查馬上有.
| First Character is Escape (27 [0x1B]) followed by... | ||||
| Key Pressed | ASCII Character | Key Pressed | ASCII Character | |
| F1 | 0x3B | INS | 0x52 | |
| F2 | 0x3C | DEL | 0x53 | |
| F3 | 0x3D | HOME | 0x47 | |
| F4 | 0x3E | END | 0x4F | |
| F5 | 0x3F | PAGE UP | 0x49 | |
| F6 | 0x40 | PAGE DOWN | 0x51 | |
| F7 | 0x41 | UP Arrow | 0x48 | |
| F8 | 0x42 | DOWN Arrow | 0x50 | |
| F9 | 0x43 | LEFT Arrow | 0x4B | |
| F10 | 0x44 | RIGHT Arrow | 0x4D | |
| F11 | 0x57 | WINDOWS | 0x5B | |
| F12 | 0x58 | Print Screen | 0x54 | |
瞧這就是答案了.嘿嘿~距離計畫完成又更進一點了.
switch(inByte) { case 0x49: Serial.print("[PgUp]"); break; case 0x51: Serial.print("[PgDn]"); break;
// defines pins numbers
const int XstepPin = 2;
const int XdirPin = 5;
const int YstepPin = 3;
const int YdirPin = 6;
// Makes pulses for making one full cycle rotation
const int pulses = 2;
void setup() {
Serial.begin(9600);
// Sets the 4 pins as Outputs
pinMode(XstepPin,OUTPUT);
pinMode(XdirPin,OUTPUT);
pinMode(YstepPin,OUTPUT);
pinMode(YdirPin,OUTPUT);
}
void loop() {
if (Serial.available() > 0) {
int inByte = Serial.read();
switch (inByte) {
//UP Arrow
case '0x48':
digitalWrite(YdirPin,HIGH); // Enables the motor to move in a particular direction
for(int y = 0; y < pulses; y++) {
digitalWrite(YstepPin,HIGH);
delayMicroseconds(50);
}
digitalWrite(YstepPin,LOW);
break;
//DOWN Arrow
case '0x50':
digitalWrite(YdirPin,LOW); // Enables the motor to move in a particular direction
for(int y = 0; y < pulses; y++) {
digitalWrite(YstepPin,HIGH);
delayMicroseconds(50);
}
digitalWrite(YstepPin,LOW);
break;
//LEFT Arrow
case '0x4B':
digitalWrite(XdirPin,LOW); // Enables the motor to move in a particular direction
for(int x = 0; x < pulses; x++) {
digitalWrite(XstepPin,HIGH);
delayMicroseconds(50);
}
digitalWrite(XstepPin,LOW);
break;
//RIGHT Arrow
case '0x4D':
digitalWrite(XdirPin,HIGH); // Enables the motor to move in a particular direction
for(int x = 0; x < pulses; x++) {
digitalWrite(XstepPin,HIGH);
delayMicroseconds(50);
}
break;
digitalWrite(XstepPin,LOW);
}
PS.文中其中提到沒有直接反應的RS232軟體.感謝Google
馬上找到免費的
沒有留言:
張貼留言