Coder Social home page Coder Social logo

arduino-ps2-mouse's Introduction

arduino-ps2-mouse

A library to interact with a PS/2 mouse. The mouse works in the remote mode, i.e. you need to explicitly ask it to send the data.

The library provides information about the pressed buttons, mouse position and the wheel(s) rotation count(s), if any. The following data structure is used:

typedef struct {
	int status;
	Position position;
	int wheel;
} MouseData;

where the Position is defined as:

typedef struct {
	int x, y;
} Position;

The position and wheel values are relative to the previously retrieved data, i.e. the are all 0's if the mouse/wheel(s) positions haven't changed since last read.

If the mouse has two wheels, the wheel value is incremented/decremented by 1 when the vertical scroll wheel is moved and incremented/decremented by 2 when the horizontal scroll wheel is moved (that's the way Microsoft has implemented their IntelliMouse standard).

See http://computer-engineering.org/ps2mouse for details.

Usage

  1. Identify the power, clock and data lines in the PS/2 cable, see http://www.computer-engineering.org/ps2protocol for details.

  2. Connect the power lines to Arduino's +5V and GND.

  3. Connect the data and clock lines to two Arduino's digital outputs.

  4. Include the header file in your sketch and create a PS2Mouse instance with the numbers of the clock and data pins as constructor parameters:

    #include "PS2Mouse.h"
    #define DATA_PIN 5
    #define CLOCK_PIN 6
    
    PS2Mouse mouse(CLOCK_PIN, DATA_PIN);
  5. Initialize the mouse in the setup():

    mouse.initialize();
  6. In the loop() use PS2Mouse::readData() to retrieve current position and wheel data, with a small delay between subsequent reads:

    MouseData data = mouse.readData();
    delay(20);

    See example.ino for a complete example.

Credits

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.