概要
arduino leonardoにps/2 マウスつないで、usbマウスをエミュレートしてみた。
写真
回路図
サンプルコード
#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);
}