http://www.arduino.cc/playground/Main/PS2Keyboard

General

The PS2Keyboard library uses one of the two available external interrupts to react on keyboard input. Once such input is received, it's stored in a one-byte buffer and is available to be read.

The following schematic shows how to connect a PS/2 connector:

Make sure you connect the Clock PIN to the digital PIN 3 on the Arduino. Otherwise the interrupt, and therefore the whole library, won't work.

Usage

Below is a simple example on how to use the library. For more keycode constants have a look at the PS2Keyboard.h file.

#include <PS2Keyboard.h>

#define DATA_PIN 4
PS2Keyboard keyboard;

void setup() {
  keyboard.begin(DATA_PIN);

  Serial.begin(9600);
  Serial.println("hi");
  delay(1000);
}

void loop() {
  if(keyboard.available()) {
    byte dat = keyboard.read();
    byte val = dat - '0';

    if(val >= 0 && val <= 9) {
      Serial.print(val, DEC);
    } else if(dat == PS2_KC_ENTER) {
      Serial.println();
    } else if(dat == PS2_KC_ESC) {
      Serial.println("[ESC]");
    } 
  }
}


Download

This library is at a very early stage. If anyone wants to revise/rewrite it, feel free to do so (published under the LGPL). Attach:PS2Keyboard002.zip

FULL KEYBOARD IMPLEMENTATION CONTAINED IN PS2Keyboard_014A

Attach:PS2Keyboard_014A.zip

NOTE: PS2Keyboard_014A is the library to use beginning with Arduino 0013. ** It contains a full complement of letters, numbers and punctuation (excluding shifted characters/symbols). **

Further readings

Suggestions

Rename charAvailable() to available() and readChar() to read() for consistency with other libraries.

Thanks for the hint. I've changed the names and updated the example. I didn't know how to reupload the file, so I changed its name. The old one (PS2Keyboard.zip) is hereby obsolete.

Bug

Missing 'byte' declaration

Can be fixed by adding

#include "binary.h"
typedef uint8_t boolean;
typedef uint8_t byte;


Reply via email to