| nRF24 | Nano | Hinweis |
|---|
| GND | GND | |
| VCC | 3.3V ❗ | |
| CE | D9 | |
| CSN | D10 | |
| MOSI | D11 | |
| MISO | D12 | |
| SCK | D13 | |
| Kondensator + | 3.3V | 10–100µF |
| Kondensator − | GND | direkt am Modul |
| Taster | Pin |
|---|
| Vorwärts | D2 |
| Rückwärts | D3 |
| Links | D4 |
| Rechts | D5 |
#include <SPI.h>
#include <RF24.h>
RF24 radio(9, 10);
const byte address[6] = "00001";
#define BTN_FWD 2
#define BTN_BACK 3
#define BTN_LEFT 4
#define BTN_RIGHT 5
void setup() {
pinMode(BTN_FWD, INPUT_PULLUP);
pinMode(BTN_BACK, INPUT_PULLUP);
pinMode(BTN_LEFT, INPUT_PULLUP);
pinMode(BTN_RIGHT, INPUT_PULLUP);
radio.begin();
radio.setPALevel(RF24_PA_MIN);
radio.setDataRate(RF24_1MBPS);
radio.setChannel(108);
radio.setRetries(15,15);
radio.openWritingPipe(address);
radio.stopListening();
}
void loop() {
byte command = 0;
if (!digitalRead(BTN_FWD)) command = 1;
else if (!digitalRead(BTN_BACK)) command = 2;
else if (!digitalRead(BTN_LEFT)) command = 3;
else if (!digitalRead(BTN_RIGHT)) command = 4;
radio.write(&command, sizeof(command));
delay(30);
}