轨迹球模块

来自YFRobotwiki
跳转至: 导航搜索
轨迹球模块


产品简介


轨迹球模块采用黑莓轨迹球设计制作,模块可以通过滚轮运动传动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 电子工作室