Joystick Shield拓展板

出自小钉锤WIKI
跳至導覽 跳至搜尋


一、Joystick Shield

1. 圖示:

11.jpg

2. 價格:

11~27元

二、接口

1. 插板式

由於這塊拓展板比較大,所以板子設計成可以直接插在Arduino上,除了幾個埠被拓展板使用以外,其他引腳插口都可以正常當成Arduino引腳被使用。

2. 連線式

如果要將拓展板分離,獨立連線,最少需要10根杜邦線。

6根控制6個按鍵,是數字引腳(D);2根控制遙杆,是模擬引腳(A);1根電源線和1根地線。

12312321.jpg

  • 電源3.3V或5V可以選其一,也可以都連接,然後在左下角的撥碼開關處進行選擇。
3.NRF24L01接口 arduino

CE_PIN  9

CSN_PIN 10

三、驅動程序

1. 遙感控制

引腳選擇:

X值接A0口

Y值接A1口

#define PIN_ANALOG_X 0
#define PIN_ANALOG_Y 1
void setup() {
 Serial.begin(9600);
}

void loop() {
 Serial.print("x: ");
 Serial.println(analogRead(PIN_ANALOG_X));
 Serial.print("y: ");
 Serial.println(analogRead(PIN_ANALOG_Y));
 delay(500);
}


2. 按鍵控制

引腳選擇:

A接D2

B接B3

C接D5

D接D4

E接D6

F接D7

#define BUTTON_UP 2
#define BUTTON_RIGHT 3
#define BUTTON_DOWN 5
#define BUTTON_LEFT 4
#define BUTTON_E 6
#define BUTTON_F 7
#define DELAY 500
void setup() {
  
 Serial.begin(9600);
 
 pinMode(BUTTON_UP, INPUT);
 digitalWrite(BUTTON_UP, HIGH);
 pinMode(BUTTON_RIGHT, INPUT);
 digitalWrite(BUTTON_RIGHT, HIGH);
 pinMode(BUTTON_DOWN, INPUT);
 digitalWrite(BUTTON_DOWN, HIGH);
 pinMode(BUTTON_LEFT, INPUT);
 digitalWrite(BUTTON_LEFT, HIGH);
 pinMode(BUTTON_E, INPUT);
 digitalWrite(BUTTON_E, HIGH);
 pinMode(BUTTON_F, INPUT);
 digitalWrite(BUTTON_F, HIGH);
 
}
void loop() {
 if(digitalRead(BUTTON_UP) == LOW) {
   Serial.println("Button A is pressed");
   delay(DELAY);
 }
 else if(digitalRead(BUTTON_RIGHT) == LOW) {
   Serial.println("Button B is pressed");
   delay(DELAY);
 }
 else if(digitalRead(BUTTON_DOWN) == LOW) {
   Serial.println("Button C is pressed");
   delay(DELAY);
 }
 else if(digitalRead(BUTTON_LEFT) == LOW) {
   Serial.println("Button D is pressed");
   delay(DELAY);
 }
 else if(digitalRead(BUTTON_E) == LOW) {
   Serial.println("Button E is pressed");
   delay(DELAY);
 }
 else if(digitalRead(BUTTON_F) == LOW) {
   Serial.println("Button F is pressed");
   delay(DELAY);
 }
}


參考資料:https://www.allaboutcircuits.com/projects/level-up-arduino-joystick-shield-v2.4/