2015年5月25日 星期一

Bluetouth Joystick on RPi2 (Python)

網路上找到一個有趣的一段程式碼

import subprocess
import pygame
pygame.init()
ps3 = pygame.joystick.Joystick(0)
ps3.init()
while True:
  try:
      pygame.event.pump()
      buttons = [ps3.get_button(0),ps3.get_button(1),ps3.get_button(2),ps3.get_button(3),ps3.get_button(4),ps3.get_button(5),ps3.get_button(6),ps3.get_button(7),ps3.get_button(8),ps3.get_button(9),ps3.get_button(10),ps3.get_button(11),ps3.get_button(12),ps3.get_button(13),ps3.get_button(14),ps3.get_button(15),ps3.get_button(16)]
      axis = [ps3.get_axis(0),ps3.get_axis(1),ps3.get_axis(2),ps3.get_axis(3)]
      print(buttons)
      print(axis)
      subprocess.call("clear")
   except KeyboardInterrupt:
      print("Exiting")
      raise

首先先將Bluetouch搖桿與RPi2連線,目前我是使用startx的方式,以圖形介面的方式去操作抓到藍芽週邊.希望有文字模式的操作方法.有空再研究
確定手把連線後.接者使用python執行這段描述.
針對Button的這個矩陣.總共會有16個參數.對應axis這各參數總共有4個參數.
目前針對WAMO Pro這隻藍芽手把抓到的位置對應為
Button=[A,B,BL,X,Y,BR,LB,RB,LT,RT,LA,RA,0,0,0,0]
Axis=[LX-,LX+,LY+,LY-,RX-,RX+,RY+,RY-]
X-min=-1;
X+max=999969482421875
Y-min=-1;
Y+max=999969482421875
這樣看來Axis為類比訊號.
Button只有On/Off的1 or 0差異.
這樣子藍芽手把可以當作搖控的設備了.現在已經知道python與手把的對應關係了.
要弄出一部藍芽遙控車也不是不可能了.
萬事不具,更欠東風啊…神啊~請賜給我一個車體基盤,加上一個L298N馬達驅動版吧..
我的霹靂車計畫就可以開動.
霹靂車,尖端科技的結晶,是一部人性化的萬能電腦車。笑~~~

1 則留言:

  1. http://www.correlatedcontent.com/blog/bluetooth-keyboard-on-the-raspberry-pi/

    回覆刪除

老玻璃也是可以上隔熱貼

多年前裝修的時候 就有想過要將客廳玻璃貼上隔熱貼 當時有很多說法,大多是這類的老玻璃有格線,有溝會貼失敗. 但如果目的是隔熱降低日照進室內的溫度,以冷房為目的.就可以犧牲貼膜有氣泡啦 畢竟玻璃這麼髒.氣泡有一點又算呢? 以此心理建設完成後.終於在達人網上找到" B.X專...