DEV-12640开发板支持hid功能,这样也就完成了我们主题鼠标和键盘功能。
首先看介绍:
我们将开发板通过micro usb线连接电脑,在驱动中可以看到已经识别到usb设备
在windows 10 的设备中,可以看到开发板的图标
由于arduio已经实现了鼠标功能,我们引用鼠标和键盘的头文件
#include <Keyboard.h>#include <Mouse.h>初始化
Keyboard.begin(); //Init keyboard emulation Mouse.begin(); //Init mouse emulation即可完成鼠标按键和键盘向电脑输入字符。
鼠标的功能和函数如下:
THE MOUSE ACTION
MOUSE_LEFT - Left mouse button
MOUSE_RIGHT - Right mouse button
MOUSE_MIDDLE - Middle mouse button
MOUSE_ALL - All three mouse buttons
THE MOUSE FUNTION
Mouse.press(MOUSE_RIGHT);
Mouse.release(MOUSE_RIGHT);
键盘的函数如下:
Keyboard.write('C') ;Keyboard.print("AC");
arduio程序中对手势做出判断,如果是对应手势则发送简写字母到电脑(电脑端使用notepad或者txt文本编辑器)
Serial.println(paj.gestureDescription(gesture)); if(paj.gestureDescription(gesture)=="Up") Keyboard.write('U') ;// This will send a single 'U' character to your computer. if(paj.gestureDescription(gesture)=="Down") Keyboard.write('W') ; if(paj.gestureDescription(gesture)=="Left") Keyboard.write('L') ; if(paj.gestureDescription(gesture)=="Right") Keyboard.write('R') ; if(paj.gestureDescription(gesture)=="Forward") Keyboard.write('F') ; if(paj.gestureDescription(gesture)=="Backward") Keyboard.write('B') ; if(paj.gestureDescription(gesture)=="Clockwise") Keyboard.write('C') ; if(paj.gestureDescription(gesture)=="Anti-Clockwise") Keyboard.print("AC");
鼠标功能实现在上面姿势的判断下,发送对应标记即可:
Mouse.press(MOUSE_LEFT);
delay(1000);
Mouse.release(MOUSE_LEFT); // release the left button
delay(1000);
Mouse.press(MOUSE_RIGHT);
delay(1000);
Mouse.release(MOUSE_RIGHT); // release the left button
delay(1000);
Keyboard.write('p') ;// This will send a single 'p' character to your computer,RETURN PPT to a forward page
至此,基本功能实现,视频在下一个帖子。