Fév 092013
 

This time lets play with Arduino and a ps2 keyboard.

For the record here comes the ps2 male connectors :

ps2_male

A quick schema :

ps2_keyboard_bb

The sketch :

#include <PS2Keyboard.h>

#define KBD_CLK_PIN  3
#define KBD_DATA_PIN 4

PS2Keyboard keyboard;

void setup ( )
{
keyboard.begin(KBD_DATA_PIN);
  Serial.begin(9600);
  delay(1000);
}

void loop ( )
{
  if(keyboard.available()) {
    // reading the "extra" bits is optional
    byte   extra = keyboard.read_extra(); // must read extra before reading the character byte
    char c = keyboard.read();
    boolean ctrl = extra & 1;  // <ctrl> is bit 0
    boolean  alt = extra & 2;  //  <alt> is bit 1
    if (ctrl) Serial.print('^');
    if (alt)  Serial.print('_');
    //if      (c==PS2_KC_UP)      Serial.print("up\n");
    //if (c==PS2_KC_DOWN)    Serial.print("down\n");
    //if (c==PS2_KC_BKSP)    Serial.print("backspace\n");
    //if (c==PS2_KC_ESC)   { Serial.print("escape and reset\n"); keyboard.reset(); }
    Serial.print(c);   //lets print last input char to our serial monitor
  }   
}

(the PS2Keyboard library : PS2Keyboard)

A picture (i used female – male proto wires so that I did not have to cut out my ps2 keyboard wire).

ps2

 Posted by at 22 h 04 min

3
Poster un Commentaire

avatar
2 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
Blog J.Schweiss | Arduino recapadminchrisotopher Recent comment authors
  Subscribe  
plus récents plus anciens
Me notifier des
chrisotopher
Invité

Please help!!!

« error: no matching function for call to ‘PS2Keyboard::begin(int)' »

trackback

[…] : display a clock based on a lcd screen and a RTC Arduino : output to a tv (tvout) Arduino : use a PS2 keyboard Arduino : send and receive data thru radio frequency (RF433) Arduino : programming an Arduino Pro […]