From 80813ed8ae88d9ce452ef48e3146c116be8834d0 Mon Sep 17 00:00:00 2001 From: "arex.huang" Date: Thu, 12 Dec 2024 18:02:26 +0800 Subject: [PATCH] fix rf24 module pin --- .../Programmable_controller.md | 43 ++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/docs/open_source_hardware/arduino_gamepad/Programmable_controller.md b/docs/open_source_hardware/arduino_gamepad/Programmable_controller.md index c0b1407..a473483 100644 --- a/docs/open_source_hardware/arduino_gamepad/Programmable_controller.md +++ b/docs/open_source_hardware/arduino_gamepad/Programmable_controller.md @@ -196,7 +196,23 @@ void loop() { } ``` -将示例程序`examples/gamepad_subscribe_rf24/gamepad_subscribe_rf24.ino`下载到接收端, 内容如下: +将示例程序`examples/gamepad_subscribe_rf24/gamepad_subscribe_rf24.ino`下载到接收端, + +*注意*: **Arduino AVR NANO 和 Arduino AVR UNO 的与RF24模块连接的引脚不一样**: + +| Arduino AVR UNO | RF2.4 Module | +| --- | --- | +| 10 | CE | +| 9 | CS | + +| Arduino AVR NANO | RF2.4 Module | +| --- | --- | +| 7 | CE | +| 8 | CS | + +所以烧录的时候选择的Arduino IDE上选择的开发板要选择正确 + +代码内容如下: ```c++ #include @@ -207,9 +223,28 @@ void loop() { emakefun::GamepadSubscriberRf24 g_gamepad_subscriber; emakefun::GamepadModel g_gamepad_model; +#if defined(ARDUINO_AVR_UNO) +constexpr uint8_t kRf24CePin = 10; +constexpr uint8_t kRf24CsPin = 9; +#elif defined(ARDUINO_AVR_NANO) +constexpr uint8_t kRf24CePin = 7; +constexpr uint8_t kRf24CsPin = 8; +#else +#error "unsupported board type" +#endif + void setup() { Serial.begin(115200); - g_gamepad_subscriber.Initialize(7, 8, 115, 5, 0x0011000011LL); +#if defined(ARDUINO_AVR_UNO) + Serial.println("Arduino AVR UNO"); +#elif defined(ARDUINO_AVR_NANO) + Serial.println("Arduino AVR NANO"); +#endif + Serial.print("rf24 ce pin: "); + Serial.print(kRf24CePin); + Serial.print(", cs pin: "); + Serial.println(kRf24CsPin); + g_gamepad_subscriber.Initialize(kRf24CePin, kRf24CsPin, 115, 5, 0x0011000011LL); g_gamepad_subscriber.AttachModel(&g_gamepad_model); Serial.println("setup done"); } @@ -504,12 +539,10 @@ bool ButtonReleased(const ButtonType button_type) const { `g_gamepad_model.GetGravityAcceleration().z` - - 以上函数直接调用即可 若遇上解决不了的问题 ## 联系我们 -**技术 + 合作:WX号: EmakefunService** \ No newline at end of file +**技术 + 合作:WX号: EmakefunService**