“轨迹球模块”的版本间的差异
来自YFRobotwiki
| (未显示1个用户的5个中间版本) | |||
| 第6行: | 第6行: | ||
=== 产品简介 === | === 产品简介 === | ||
<br> | <br> | ||
| − | 轨迹球模块 | + | 轨迹球模块 采用黑莓轨迹球设计制作,模块可以通过滚轮运动传动X和Y方向的转轴,通过固定在转轴上的多极充磁磁体转动,对相应的SMD霍尔元件发出信号,从而确定运动轨迹。轨迹球下方还设计了一个小SMD开关,方便用户进行触发事件或“点击”选择。 |
| 第92行: | 第92行: | ||
:'''示例代码''' | :'''示例代码''' | ||
| − | < | + | <source lang="c"> |
| − | // | + | /************************************************************************** |
| + | BlackBerry Trackballer Breakout Demo | ||
| + | ***************************************************************************/ | ||
| + | //Define Trackballer Breakout pin connections to Arduino | ||
| + | #define Btn 2 | ||
| + | #define Lft 3 | ||
| + | #define Rht 4 | ||
| + | #define Up 5 | ||
| + | #define Dwn 6 | ||
| − | + | //Define variables used in sketch | |
| − | + | int buttonClick; | |
| + | unsigned long mouse_Lft; | ||
| + | unsigned long old_mouse_Lft; | ||
| + | unsigned long mouse_Rht; | ||
| + | unsigned long old_mouse_Rht; | ||
| + | unsigned long mouse_Up; | ||
| + | unsigned long old_mouse_Up; | ||
| + | unsigned long mouse_Dwn; | ||
| + | unsigned long old_mouse_Dwn; | ||
| + | int x_position; | ||
| + | int y_position; | ||
| + | /*********************Setup Loop*************************/ | ||
void setup() { | void setup() { | ||
| − | pinMode( | + | |
| + | //Define pin functionality on the Arduino | ||
| + | pinMode(Btn, INPUT); | ||
| + | pinMode(Lft, INPUT); | ||
| + | pinMode(Rht, INPUT); | ||
| + | pinMode(Up, INPUT); | ||
| + | pinMode(Dwn, INPUT); | ||
| + | |||
| + | //Start Serial port for debugging. | ||
| + | Serial.begin(9600); | ||
| + | Serial.println("Begin Trackballer Demo"); | ||
| + | delay(1000); | ||
| + | Serial.println("Begin Trackball tracking"); | ||
} | } | ||
| + | |||
| + | |||
| + | /*********************Main Loop*************************/ | ||
void loop() { | void loop() { | ||
| + | //read the pin state | ||
| + | mouse_Lft = digitalRead(Lft); | ||
| + | mouse_Rht = digitalRead(Rht); | ||
| + | if (mouse_Lft != old_mouse_Lft) | ||
| + | { | ||
| + | x_position = --x_position; | ||
| + | old_mouse_Lft = mouse_Lft; | ||
| + | Serial.print("Trackball Position: \t X-Position= "); | ||
| + | Serial.println(x_position); | ||
| + | } | ||
| + | if (mouse_Rht != old_mouse_Rht) | ||
| + | { | ||
| + | x_position = ++x_position; | ||
| + | old_mouse_Rht = mouse_Rht; | ||
| + | Serial.print("Trackball Position: \t X-Position= "); | ||
| + | Serial.println(x_position); | ||
| + | } | ||
| + | delay(50); | ||
| + | //read the pin state | ||
| + | mouse_Up = digitalRead(Up); | ||
| + | mouse_Dwn = digitalRead(Dwn); | ||
| + | if (mouse_Up != old_mouse_Up) | ||
| + | { | ||
| + | y_position = ++y_position; | ||
| + | old_mouse_Up = mouse_Up; | ||
| + | Serial.print("Trackball Position: \t \t Y-position= "); | ||
| + | Serial.println(y_position); | ||
| + | } | ||
| + | if (mouse_Dwn != old_mouse_Dwn) | ||
| + | { | ||
| + | y_position = --y_position; | ||
| + | old_mouse_Dwn = mouse_Dwn; | ||
| + | Serial.print("Trackball Position: \t \t Y-position= "); | ||
| + | Serial.println(y_position); | ||
| + | } | ||
| + | delay(50); | ||
| − | + | //Check for button click. If present, print to Serial monitor. | |
| − | + | buttonClick = digitalRead(Btn); | |
| − | + | if (buttonClick == LOW) | |
| − | + | { | |
| + | Serial.println("Click"); | ||
| + | } | ||
} | } | ||
| − | </ | + | </source> |
| − | 程序下载地址:[ | + | 程序下载地址:[https://eyun.baidu.com/s/3mispQPU BlackBerry_Trackballer_Breakout_Demo] |
| − | 程序运行结果:轨迹球 | + | 程序运行结果: 转动 轨迹球 ,串口输出X、Y轴位置信息,点击按键串口输出“Click”。串口监视器截图: |
| + | [[Image:轨迹球串口输出.png|center|轨迹球串口输出]] | ||
| + | |||
| + | [http://www.yfrobot.com/thread-11709-1-1.html 教程地址附视频] | ||
===参考资料=== | ===参考资料=== | ||
<br> | <br> | ||
| − | |||
| 第126行: | 第200行: | ||
[[首页 | 返回首页]] | [[首页 | 返回首页]] | ||
| + | |||
| + | 欢迎交流加入群聊-[https://jq.qq.com/?_wv=1027&k=466mOjv 技术交流群] | ||
更多建议和问题欢迎反馈至 [http://www.yfrobot.com YFRobot论坛] | 更多建议和问题欢迎反馈至 [http://www.yfrobot.com YFRobot论坛] | ||
购买方式:[http://yfrobot.taobao.com/ YFRobot 电子工作室] | 购买方式:[http://yfrobot.taobao.com/ YFRobot 电子工作室] | ||
2020年4月10日 (五) 11:26的最后版本
产品简介
轨迹球模块采用黑莓轨迹球设计制作,模块可以通过滚轮运动传动X和Y方向的转轴,通过固定在转轴上的多极充磁磁体转动,对相应的SMD霍尔元件发出信号,从而确定运动轨迹。轨迹球下方还设计了一个小SMD开关,方便用户进行触发事件或“点击”选择。
规格参数
- 供电电压:DC3.3 - 5V
- 安装孔径:3MM
- 模块尺寸:28*21*15.7MM(长*宽*高)
- 孔间距:15MM
- 模块重量:2.5g
引脚说明
| 名称 | 说明 |
| RHT | Sign - right |
| LET | Sign - left |
| DWN | Sign - down |
| UP | Sign - up |
| KEY | Sign - key |
| VCC | 电源+5V |
| GND | 地 |
应用示例
- 电路连接示意图
| 轨迹球模块 | Arduino UNO |
| RHT | D4 |
| LET | D3 |
| DWN | D6 |
| UP | D5 |
| KEY | D2 |
| VCC | 电源+5V |
| GND | 地 |
- 示例代码
/************************************************************************** BlackBerry Trackballer Breakout Demo ***************************************************************************/ //Define Trackballer Breakout pin connections to Arduino #define Btn 2 #define Lft 3 #define Rht 4 #define Up 5 #define Dwn 6 //Define variables used in sketch int buttonClick; unsigned long mouse_Lft; unsigned long old_mouse_Lft; unsigned long mouse_Rht; unsigned long old_mouse_Rht; unsigned long mouse_Up; unsigned long old_mouse_Up; unsigned long mouse_Dwn; unsigned long old_mouse_Dwn; int x_position; int y_position; /*********************Setup Loop*************************/ void setup() { //Define pin functionality on the Arduino pinMode(Btn, INPUT); pinMode(Lft, INPUT); pinMode(Rht, INPUT); pinMode(Up, INPUT); pinMode(Dwn, INPUT); //Start Serial port for debugging. Serial.begin(9600); Serial.println("Begin Trackballer Demo"); delay(1000); Serial.println("Begin Trackball tracking"); } /*********************Main Loop*************************/ void loop() { //read the pin state mouse_Lft = digitalRead(Lft); mouse_Rht = digitalRead(Rht); if (mouse_Lft != old_mouse_Lft) { x_position = --x_position; old_mouse_Lft = mouse_Lft; Serial.print("Trackball Position: \t X-Position= "); Serial.println(x_position); } if (mouse_Rht != old_mouse_Rht) { x_position = ++x_position; old_mouse_Rht = mouse_Rht; Serial.print("Trackball Position: \t X-Position= "); Serial.println(x_position); } delay(50); //read the pin state mouse_Up = digitalRead(Up); mouse_Dwn = digitalRead(Dwn); if (mouse_Up != old_mouse_Up) { y_position = ++y_position; old_mouse_Up = mouse_Up; Serial.print("Trackball Position: \t \t Y-position= "); Serial.println(y_position); } if (mouse_Dwn != old_mouse_Dwn) { y_position = --y_position; old_mouse_Dwn = mouse_Dwn; Serial.print("Trackball Position: \t \t Y-position= "); Serial.println(y_position); } delay(50); //Check for button click. If present, print to Serial monitor. buttonClick = digitalRead(Btn); if (buttonClick == LOW) { Serial.println("Click"); } }
程序下载地址:BlackBerry_Trackballer_Breakout_Demo
程序运行结果:转动轨迹球,串口输出X、Y轴位置信息,点击按键串口输出“Click”。串口监视器截图:
参考资料
欢迎交流加入群聊-技术交流群
更多建议和问题欢迎反馈至 YFRobot论坛
购买方式:YFRobot 电子工作室
