LoginSignup
6
7

More than 5 years have passed since last update.

arduinoでps/2 mouse

Last updated at Posted at 2016-04-11

概要

arduino leonardoにps/2 マウスつないで、usbマウスをエミュレートしてみた。

写真

MVC-004S.JPG

回路図

mouse.JPG

サンプルコード

#include "ps2.h"

PS2 mos(6, 5);
void mos_init()
{
    mos.write(0xff);
    mos.read();
    mos.read();
    mos.read();
    mos.write(0xf0);
    mos.read();
    delayMicroseconds(100);
}
void setup()
{
    Serial.begin(115200);
    while (!Serial);
    Serial.println("Start");
    mos_init();
    Mouse.begin();
    Serial.println("OK");
}
void loop()
{
    char mstat;
    char mx;
    char my;
    mos.write(0xeb);
    mos.read();
    mstat = mos.read();
    mx = mos.read();
    my = mos.read();
    Serial.print(mstat, BIN);
    Serial.print("\tX=");
    Serial.print(mx, DEC);
    Serial.print("\tY=");
    Serial.print(my, DEC);
    Serial.println();
    //Mouse.press();
    Mouse.move(mx, my, 0);
    //Mouse.release();
    delay(100);
}

6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7