I'm using the MiRF library to make several nRF24L01+ modules talk to one another. One of them is designated a "master" in that it tells the others what they should be doing. Sending data out is done with the following call:
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
void transmit(const int seq) {
byte c;
c = seq;
Mirf.send(&c);
while (Mirf.isSending());
}
void setup() {
Mirf.cePin = 7;
Mirf.csnPin = 8;
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.payload = 2;
Mirf.channel = 5;
Mirf.config();
Mirf.configRegister(RF_SETUP,0x06);
}
void loop() {
// I'm only sending out numbers
for (int data = 0; data < 5; data++) {
Mirf.setTADDR((byte*)"RC_01");
transmit(data);
}
}
My problem is that I have several "RC_" modules, each one has a different number (from 01 to 13) ...
How can I construct that string piece "RC_" with the number behind and pass that to the Mirf call? Using the String() object doesn't work because of different types. For example:
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
String rcvrString;
String rcvrName;
void transmit(const int seq) {
byte c;
c = seq;
Mirf.send(&c);
while (Mirf.isSending());
}
void setup() {
Mirf.cePin = 7;
Mirf.csnPin = 8;
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.payload = 2;
Mirf.channel = 5;
Mirf.config();
Mirf.configRegister(RF_SETUP,0x06);
rcvrString = String("RC_");
rcvrName = String();
}
void loop() {
// I'm only sending out numbers
for (int data = 0; data < 5; data++) {
// cycle through all receivers
for (int rcvr = 0; rcvr < 15; rcvr++) {
rcvrName = rcvrString + String(rcvr); // this does create the correct information in rcvrName
Mirf.setTADDR((byte*)rcvrName); // this fails with 'invalid cast from type 'String' to type 'byte*'
transmit(data);
}
}
}
I was kinda expecting that error since I'm working with the String() object, and the .setTADDR() command is doing a byte cast. Question is, how do I do this properly?