uint8_t address[][6] = { "1Node", "2Node" };
bool radioNumber = 1;
bool role = false;
float payload = 0.0;
void setup() {
while (!Serial) {
}
Serial.println(F("radio hardware is not responding!!"));
while (1) {}
}
Serial.println(F("RF24/examples/GettingStarted"));
Serial.println(F("Which radio is this? Enter '0' or '1'. Defaults to '0'"));
while (!Serial.available()) {
}
char input = Serial.parseInt();
radioNumber = input == 1;
Serial.print(F("radioNumber = "));
Serial.println((int)radioNumber);
Serial.println(F("*** PRESS 'T' to begin transmitting to the other node"));
if (role) {
} else {
}
}
void loop() {
if (role) {
unsigned long start_timer = micros();
bool report = radio.
write(&payload,
sizeof(
float));
unsigned long end_timer = micros();
if (report) {
Serial.print(F("Transmission successful! "));
Serial.print(F("Time to transmit = "));
Serial.print(end_timer - start_timer);
Serial.print(F(" us. Sent: "));
Serial.println(payload);
payload += 0.01;
} else {
Serial.println(F("Transmission failed or timed out"));
}
delay(1000);
} else {
uint8_t pipe;
radio.
read(&payload, bytes);
Serial.print(F("Received "));
Serial.print(bytes);
Serial.print(F(" bytes on pipe "));
Serial.print(pipe);
Serial.print(F(": "));
Serial.println(payload);
}
}
if (Serial.available()) {
char c = toupper(Serial.read());
if (c == 'T' && !role) {
role = true;
Serial.println(F("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK"));
} else if (c == 'R' && role) {
role = false;
Serial.println(F("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK"));
}
}
}
Driver class for nRF52840 2.4GHz Wireless Transceiver.
void startListening(bool resetAddresses=true)
void openReadingPipe(uint8_t child, const uint8_t *address)
void setPALevel(uint8_t level, bool lnaEnable=true)
bool write(void *buf, uint8_t len, bool multicast=false, bool doEncryption=true)
void openWritingPipe(const uint8_t *address)
void read(void *buf, uint8_t len)
void stopListening(bool setWritingPipe=true, bool resetAddresses=true)
void setPayloadSize(uint8_t size)