###### tags: `Arduino` `Arduino 實作` # NRF遙控端程式 ```cpp= #include<Streaming.h> #include <SPI.h> #include <printf.h> #include "RF24.h" RF24 rf24(9, 10); // CE腳, CSN腳 const byte addr[] = "1Node"; int dt[8] = {0,0,0,0}; /*joystick value x&y axis*/ const int joystick[4] = {A2,A3,A4,A5}; const int btm[4] = {2,3,4,5}; void setup() { Serial.begin(9600); rf24.begin(); rf24.setChannel(83); // 設定頻道編號 rf24.openWritingPipe(addr); // 設定通道位址 rf24.setPALevel(RF24_PA_MAX); // 設定廣播功率 rf24.setDataRate(RF24_2MBPS); // 設定傳輸速率 rf24.stopListening(); // 停止偵聽;設定成發射模式 //rf24.printDetails(); // 顯示現在狀態 for(int i=0;i<4;i++){ pinMode(joystick[i],INPUT); } for(int i=0;i<4;i++){ pinMode(btm[i],INPUT); } } void loop() { dt[0] = 526-analogRead(joystick[0]); dt[1] = 519-analogRead(joystick[1]); dt[2] = 504-analogRead(joystick[2]); dt[3] = 510-analogRead(joystick[3]); for(int i=0;i<4;i++){ Serial << dt[i] << " "; } Serial << endl; rf24.write(&dt, sizeof(dt)); // 傳送資料 delay(10); } ```