Keyboard dan mouse merupakan perangkat PC (personal computer) yang berfungsi sebagai interface atau perantara antara pengguna dan pc. Perangkat ini umumnya terhubung menggunakan interface usb, akan tetapi umumnya keyboard dan mouse juga memiliki interface PS2 dan AT Bus.
PS2
PS2 atau Personal System/2 adalah salah satu protokol komunikasi antara komputer dan perangkat lain yang dikembangkan pada tahun 1987. Untuk keyboard dan mouse standar soket PS2-nya berbentuk seperti ini :
AT Bus
AT atau advanced technology bus dikembangkan pada tahun 1984. Standar interface AT Bus untuk keyboad berbentuk seperti ini:
USB Keyboard / mouse
Saat sekarang keyboad dan mouse dengan interface PS2 dan AT bus sudah tidak ditemukan yang digantikan dengan soket dengan interface USB. Namun kebanyakan keyboard dan mouse masih mendukung interface PS2 dengan kombinasi sebagai berikut :
Skema penggunaan keyboard dan mouse sebagai input
contoh sketch/program arduino menggunakan keyboard
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | #include <PS2_Semesin.h> #include <LiquidCrystal_I2C.h> #include <PS2Code.h> #define keyboardDATAPIN 4 #define keyboardClockPIN 3 #define MAX_COL 16 #define MAX_ROW 2 int8_t cols = 0; int8_t rows = 0; LiquidCrystal_I2C lcd(0x3F, MAX_COL, MAX_ROW); PS2 keyboard; void setup() { Serial.begin(9600); Serial.println( "Keyboard arduino dengan tampilan I2C LCD" ); Serial.println(); Wire.begin(); Wire.beginTransmission(0x3F); if (Wire.endTransmission()) { lcd = LiquidCrystal_I2C(0x27, 16, 2); } lcd.begin(); lcd.backlight(); keyboard.begin( keyboardDATAPIN, keyboardClockPIN ); keyboard.setNoBreak(1); keyboard.setNoRepeat( 1 ); } void loop() { if ( keyboard.available() ) { char keyboardData = keyboard.read(); if (keyboardData >= ' ' && keyboardData <= '~' ) { lcd.print(keyboardData); cols++; if ( cols >= MAX_COL ) { cols = 0; rows++; if ( rows >= MAX_ROW ) { rows = 0; } } lcd.setCursor( cols, rows ); Serial.print(keyboardData); } else { Serial.println(); Serial.print( "Special char = " ); Serial.println(keyboardData,HEX); switch ( keyboardData ) { case PS2_KEY_ENTER: case PS2_KEY_KP_ENTER: cols = 0; rows++; if ( rows >= MAX_ROW ) rows = 0; break ; case PS2_KEY_PGDN: rows = MAX_ROW - 1; break ; case PS2_KEY_PGUP: rows = 0; break ; case PS2_KEY_L_ARROW: cols--; if ( cols < 0 ) { cols = MAX_COL - 1; rows--; if ( rows < 0 ) rows = MAX_ROW - 1; } break ; case PS2_KEY_R_ARROW: cols++; if ( cols >= MAX_COL ) { cols = 0; rows++; if ( rows >= MAX_ROW ) rows = 0; } break ; case PS2_KEY_UP_ARROW: rows--; if ( rows < 0 ) rows = 0; break ; case PS2_KEY_DN_ARROW: rows++; if ( rows >= MAX_ROW ) rows = MAX_ROW - 1; break ; case PS2_KEY_BS: cols--; if ( cols < 0 ) { cols = MAX_COL - 1; rows--; if ( rows < 0 ) rows = MAX_ROW - 1; } lcd.setCursor( cols, rows ); lcd.write( ' ' ); break ; case PS2_KEY_HOME: cols = 0; rows = 0; break ; case PS2_KEY_END: cols = MAX_COL - 1; rows = MAX_ROW - 1; break ; } lcd.setCursor( cols, rows ); } } } |
library LiquidCrystal-I2C.zip, PS2_Semesin.zip