軌跡球模塊
出自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 電子工作室