#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
byte TXADDR[5] = {0xff, 0xff, 0xff, 0xff, 0xff};
void setup() {
Serial.begin(115200);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(2, INPUT);
//Depending on the pins used in the hardware circuit
Mirf.cePin = 10; //CE
Mirf.csnPin = 9; //CSN
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
//Set the send destination The destination address is the receiver's own address
Mirf.setTADDR((byte *)TXADDR);
Mirf.payload = 32; //32-byte payload
Mirf.channel = 0; //2.4GHz
Mirf.config();
Serial.println("Beginning ... ");
}
uint8_t data_buff[32];
void loop() {
//Read the sensor
data_buff[0] = 10;
data_buff[1] = '{';
data_buff[2] = digitalRead(2)+'0';
data_buff[3] = '}';
data_buff[4] = '\r';
data_buff[5] = '\n';
//Set the sending destination
Mirf.setTADDR((byte*)TXADDR);
//Wireless Transmission Sending
Mirf.send((byte*)data_buff);
//Wait for sending to complete
while (Mirf.isSending()) {
}
for (int i = 1; i < 5; i++)
{
Serial.print(data_buff);
}
Serial.println();
//Time delay
delay(100);
}