Funksender

nRF24NanoHinweis
GNDGND
VCC3.3V ❗
CED9
CSND10
MOSID11
MISOD12
SCKD13
Kondensator +3.3V10–100µF
Kondensator −GNDdirekt am Modul
TasterPin
VorwärtsD2
RückwärtsD3
LinksD4
RechtsD5

#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);
}

Schreibe einen Kommentar