引腳需要與程序相對應(yīng)
接收器轉(zhuǎn)接板
接收器引腳說明
程序分析
1. 首先將文件PS2X_lib.cpp,PS2X_lib.h拷貝到項(xiàng)目文件夾下。
2. 添加頭文件。
3. 遙控接收器引腳聲明(需要跟實(shí)際連線相對應(yīng))。
4. 實(shí)例化一個(gè)PS2對象
5. arduino初始化
ps2x.config_gamepad(PS2_CLK, PS2_CMD, PS2_CS, PS2_DAT, pressures, rumble);
PS2引腳初始化,返回值為0說明遙控連接成功。
6. 在循環(huán)中讀取遙控?cái)?shù)據(jù)
ps2x.read_gamepad(false, 0);
You must Read Gamepad to get new values and set vibration values
ps2x.read_gamepad(small motor on/off, larger motor strenght from 0-255),if
you don't enable the rumble, use ps2x.read_gamepad(); with no values。You
should call this at least once a second。
PS2遙控內(nèi)部是有兩個(gè)震動馬達(dá)的,這里我們不使用。
調(diào)用此函數(shù)讀取遙控器狀態(tài),每個(gè)循環(huán)調(diào)用一次,但不要太頻繁。
按鍵狀態(tài)讀取有三個(gè)函數(shù)
ps2x.Button( x ) ,只要按鍵按下會一直觸發(fā),按下時(shí)串口一直打印數(shù)據(jù)。
ps2x.ButtonPressed(x),按鍵按下時(shí)觸發(fā)一次,按下時(shí)串口只打印一次數(shù)據(jù)。
ps2x.ButtonReleased(x),按鍵釋放時(shí)觸發(fā)一次,松開時(shí)串口只打印一次數(shù)據(jù)。
x表示按鍵的宏定義,
具體效果請自行測試。
搖桿數(shù)據(jù)讀取
ps2x.Analog( x ) ,x表示搖桿的宏定義,具體如下圖:
遙控讀取數(shù)據(jù)的教程就到這里了,按鍵的具體功能就需要結(jié)合自己的機(jī)器人使用
了。