5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

arduinoでps/2 keyboard

Last updated at Posted at 2016-04-11

概要

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

写真

MVC-003S.JPG

回路図

key.JPG

サンプルコード

# include "ps2.h"

# define PS2_TAB				9
# define PS2_ENTER			13
# define PS2_BACKSPACE		127
# define PS2_ESC				27
# define PS2_INSERT			0
# define PS2_DELETE			127
# define PS2_HOME			0
# define PS2_END				0
# define PS2_SCROLL			0
PS2 kbd(6, 5);
char key[140] = {
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, PS2_TAB, '`', 0,
	0, 0, 0, 0, 0, 'q', '1', 0,
	0, 0, 'z', 's', 'a', 'w', '2', 0,
	0, 'c', 'x', 'd', 'e', '4', '3', 0,
	0, ' ', 'v', 'f', 't', 'r', '5', 0,
	0, 'n', 'b', 'h', 'g', 'y', '6', 0,
	0, 0, 'm', 'j', 'u', '7', '8', 0,
	0, ',', 'k', 'i', 'o', '0', '9', 0,
	0, '.', '/', 'l', ';', 'p', '-', 0,
	0, 0, '\'', 0, '[', '=', 0, 0,
	0, 0, PS2_ENTER, ']', 0, '\\', 0, 0,
	0, 0, 0, 0, 0, 0, PS2_BACKSPACE, 0,
	0, '1', 0, '4', '7', 0, 0, 0,
	'0', '.', '2', '5', '6', '8', PS2_ESC, 0,
	0, '+', '3', '-', '*', '9', PS2_SCROLL, 0,
	0, 0, 0, 0
};
void kbd_init()
{
	char ack;
	kbd.write(0xff);
	ack = kbd.read();
	ack = kbd.read();
}
void setup()
{
	Serial.begin(115200);
	while (!Serial);
	Serial.println("Start");
	kbd_init();
	Keyboard.begin();
	Serial.println("OK");
}
void loop()
{
	unsigned char code;
	for ( ; ; )
	{
		code = kbd.read();
		code = key[code];
		Serial.println(code, HEX);
		Keyboard.print((char) code);
		code = kbd.read();
		code = kbd.read();
	}
}

5
4
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
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?