- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
Arduino - 鼠标按钮控制
Arduino - ⿏标按钮控制
使⽤⿏标库,您可以使⽤Arduino Leonardo ,Micro或Due来控制计算机的屏幕光标。
此特定⽰例使⽤五个按钮来移 屏幕上的光标。 四个按钮是定向的(上,下,左,
右) ,⼀个是⽤于⿏标左键单击。 来⾃Arduino的光标移 总是相对的。 每次读取输⼊
时,相对于其当前位置更新光标的位置。
每当按下⼀个⽅向按钮时,Arduino将移 ⿏标,将HIGH输⼊映射到适当⽅向的范围
5 。
第五按钮⽤于控制来⾃⿏标的左击。 当按钮被释放时,计算机将识别事件。
必需的组件
您将需要以下组件 -
1 × Breadboard ⾯包板
1 × Arduino Leonardo , Micro 或 Due board
5 × 10k欧姆电阻
5 × momentary ushbuttons 瞬时按钮
程序
按照电路图并挂接⾯包板上的组件,如下图所⽰。
草图
在计算机上打开Arduino IDE软件。 在Arduino语⾔编码将控制你的电路。 通过单击新
建打开⼀个新的草图⽂件。
对于本例,您需要使⽤Arduino IDE 1.6.7
Arduino代码
/*
Button Mouse Control
For Leonardo and Due boards only .Controls the mouse from
five pushbuttons on an Arduino Leonardo, Micro or Due.
ardware:
* 5 pushbuttons attached to D2, D3, D4, D5, D6
The mouse movement is always relative. This sketch reads
four pushbuttons, and uses them to set the movement of the mous
WARNING: When you use the Mouse.move() command, the Arduino tak
over your mouse! Make sure you have control before you use the
*/
#include Mouse.h
// set pin numbers for the five buttons:
const int upButton = 2;
const int downButton = 3;
const int leftButton = 4;
const int rightButton = 5;
const int mouseButton = 6;
int range = 5; // output range of X or Y movement; affects movemen
int responseDelay = 10; // response delay of the mouse, in ms
void setup() {
// initialize the buttons inputs:
pinMode(upButton, INPUT);
pinMode(downButton, INPUT);
pinMode(leftButton, INPUT);
pinMode(rightButton, INPUT);
pinMode(mouseButton, INPUT);
// initialize mouse control:
Mouse.begin();
}
void loop() {
// read the buttons:
int upState = digitalRead(upButton);
int downState = digitalRead(downButton);
int rightState = digitalRead(rightButton);
int leftState = digitalRead(leftButton);
int clickState = digitalRead(mouseButton);
// calculate the movement distance based on the button states:
int xD
您可能关注的文档
最近下载
- DB41T 2412-2023 高标准农田建设规范.docx VIP
- DB11_T 387.1-2016 水利工程施工质量评定 第1部分:河道整治.PDF VIP
- IPC-1602-CN:2020+印制板操作和储存标准+-+完整中文电子版(36页).pdf VIP
- 肝病相关血小板减少症临床管理中国专家共识2023解读.pptx VIP
- 夏枯草种植技术规程.pdf VIP
- 【室内装修施工组织设计】.docx VIP
- 生物物理学导论-08省名师优质课获奖课件市赛课一等奖课件.ppt VIP
- DB41_T 2416-2023 高标准农田 智慧灌溉技术规程.docx VIP
- 棉纺织生产工艺流程大全.pdf VIP
- 生物物理学课件.docx VIP
文档评论(0)